Documentation

Documentation versions (currently viewingVaadin 23)

You are viewing documentation for Vaadin 23. View latest documentation

Basic Layouts

Vaadin features two basic layout components: Vertical Layout and Horizontal Layout. As their names suggest, they render their contents vertically and horizontally, respectively. Components are shown in the order they are added to either layout.

Vertical Layout

Vertical Layout places components top-to-bottom in a column. By default, it has 100% width and undefined height, meaning its width is constrained by its parent component and its height is determined by the components it contains.

Open in a
new tab
Source code
basic-layouts-vertical-layout.ts
BasicLayoutsVerticalLayout.java

Components in a Vertical Layout can be aligned both vertically and horizontally.

Vertical Alignment

You can position components at the top, middle, or bottom. Alternatively, you can position components by specifying how a layout’s excess space (if any) is distributed between them.

Open in a
new tab
Source code
basic-layouts-vertical-layout-vertical-alignment.ts
BasicLayoutsVerticalLayoutVerticalAlignment.java
Value Description

START (default)

Positions items at the top.

CENTER

Vertically centers items.

END

Positions items at the bottom.

BETWEEN

Available space is distributed evenly between items. No space is added before the first item, or after the last.

AROUND

Available space is distributed evenly between items. The space before the first item, and after the last, is half of that between items.

EVENLY

Available space is distributed evenly between items. The space before the first item, between items and after the last item is the same.

Horizontal Alignment

Components in a Vertical Layout can be left-aligned (default), centered, right-aligned or stretched horizontally.

Open in a
new tab
Source code
basic-layouts-vertical-layout-horizontal-alignment.ts
BasicLayoutsVerticalLayoutHorizontalAlignment.java
Value Description

START (default)

Left-aligns (in left-to-right languages) or right-aligns (in right-to-left languages) items

CENTER

Horizontally centers items

END

Right-aligns (in left-to-right languages) or left-aligns (in right-to-left languages) items

STRETCH

Stretches items with undefined width horizontally

It’s also possible to horizontally align individual components, overriding the alignment set by the parent layout.

Open in a
new tab
Source code
basic-layouts-vertical-layout-individual-alignment.ts
BasicLayoutsVerticalLayoutIndividualAlignment.java

Horizontal Layout

Horizontal Layout places components side-by-side in a row. By default, it has undefined width and height, meaning its size is determined by the components it contains.

Open in a
new tab
Source code
basic-layouts-horizontal-layout.ts
BasicLayoutsHorizontalLayout.java

Like Vertical Layout, Horizontal Layout enables both vertical and horizontal alignment of components.

Vertical Alignment

You can position components at the top, middle, or bottom. Items can alternatively be made to stretch vertically or be positioned along the layout’s text baseline.

Open in a
new tab
Source code
basic-layouts-horizontal-layout-vertical-alignment.ts
BasicLayoutsHorizontalLayoutVerticalAlignment.java
Value Description

STRETCH (default)

Stretches items with undefined height horizontally

START

Positions items at the top of the layout

CENTER

Vertically centers items

END

Positions items at the bottom of the layout

BASELINE

Position items along the layout’s (text) baseline.

It’s also possible to vertically align individual components, overriding the alignment set by the parent layout.

Open in a
new tab
Source code
basic-layouts-horizontal-layout-individual-alignment.ts
BasicLayoutsHorizontalLayoutIndividualAlignment.java

Horizontal Alignment

Components in a Horizontal Layout can be left-aligned, centered or right-aligned. Alternatively, you can position components by specifying how a layout’s excess space is distributed between them.

Open in a
new tab
Source code
basic-layouts-horizontal-layout-horizontal-alignment.ts
BasicLayoutsHorizontalLayoutHorizontalAlignment.java
Value Description

START (default)

Left-aligns (in left-to-right languages) or right-aligns (in right-to-left languages) items

END

Right-aligns (in left-to-right languages) or left-aligns (in right-to-left languages) items

CENTER

Horizontally centers items

BETWEEN

Available space is distributed evenly between items. No space is added before the first item, or after the last.

AROUND

Available space is distributed evenly between items. The space before the first item, and after the last, is half of that between items.

EVENLY

Available space is distributed evenly between items. The space before the first item, between items and after the last item is the same.

Spacing

Spacing is used to create space between components in the same layout. Spacing can help prevent mis-clicks and distinguish content areas.

Open in a
new tab
Source code
basic-layouts-spacing.ts
BasicLayoutsSpacing.java

Five different spacing theme variants are available:

Open in a
new tab
Source code
basic-layouts-spacing-variants.ts
BasicLayoutsSpacingVariants.java
Theme variant Usage recommendations

spacing-xs

Extra-small space between items

spacing-s

Small space between items

spacing

Medium space between items

spacing-l

Large space between items

spacing-xl

Extra-large space between items

Padding

Padding is the space between a layout’s outer border and its content. Padding can help distinguish a layout’s content from its surroundings. Padding is applied using the padding theme variant.

Open in a
new tab
Source code
basic-layouts-padding.ts
BasicLayoutsPadding.java

Margin

Use margin to create space around a layout.

Open in a
new tab
Source code
basic-layouts-margin.ts
BasicLayoutsMargin.java

Expanding Items

Components can be made to expand and take up any excess space a layout may have.

Open in a
new tab
Source code
basic-layouts-expanding-items.ts
BasicLayoutsExpandingItems.java

When multiple components expand, they do so relative to each other. For example, having two items with expand ratios of 2 and 1 results in the first item taking up twice as much of the available space as the second item.

6F65485D-060C-4B0C-B77C-22FB219937D7