Skip to content

HorizontalLayout

Arranges its children side by side in a row.

new HorizontalLayout(new Text("Left"), new Text("Right"))
PropertyTypeDefaultDescription
idStringOptional component ID
contentList<Component>Child components placed left to right
spacingbooleanfalseAdds gap between children
paddingbooleanfalseAdds inner padding
marginbooleanfalseAdds outer margin
spacingVariantSpacingVariantControls spacing size
verticalAlignmentVerticalAlignmentAligns children vertically (start, center, end, stretch)
justificationHorizontalLayoutJustificationSpace 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
styleStringInline CSS
cssClassesStringCSS 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()