Skip to content

HorizontalLayout

Arranges its children side by side in a row.

new HorizontalLayout(new Text("Left"), new Text("Right"))
PropertyTypeDefaultDescription
idString—Optional component ID
contentList<Component>—Child components placed left to right
spacingbooleanfalseAdds gap between children
paddingbooleanfalseAdds inner padding
marginbooleanfalseAdds outer margin
spacingVariantSpacingVariant—Controls spacing size
verticalAlignmentVerticalAlignment—Aligns children vertically (start, center, end, stretch)
justificationHorizontalLayoutJustification—Space distribution (start, end, between, around, evenly)
wrapbooleanfalseWraps children to the next row when they overflow
flexGrowsList<Integer>[]Flex-grow values per child
fullWidthbooleanfalseStretches to full width
styleString—Inline CSS
cssClassesString—CSS class names
// varargs
new HorizontalLayout(comp1, comp2)
// from list
new HorizontalLayout(List.of(comp1, comp2))
HorizontalLayout.builder()
.content(List.of(new Text("A"), new Text("B"), new Text("C")))
.spacing(true)
.verticalAlignment(VerticalAlignment.center)
.justification(HorizontalLayoutJustification.between)
.build()
HorizontalLayout.builder()
.content(List.of(new Text("Left"), new Text("Right")))
.fullWidth(true)
.justification(HorizontalLayoutJustification.between)
.build()

Assign different widths by setting flexGrows. The values map positionally to each child.

HorizontalLayout.builder()
.content(List.of(col1, col2, col3))
.flexGrows(List.of(2, 1, 1)) // col1 gets twice as much space
.build()