Documentation

Documentation versions (currently viewingVaadin 24.4 (pre))

Vertical Layout

Vertical Layout places components top-to-bottom in a column.

Vertical Layout places components top-to-bottom in a column. By default, it has a width of 100% and an undefined height. Its width is constrained by its parent component (i.e., it “fills” the available space). Whereas, its height is determined by the components it contains (i.e., it “hugs” its content).

See Horizontal Layout for information on placing components side-by-side.

Open in a
new tab
<vaadin-vertical-layout theme="spacing padding">
  <vaadin-button>Button 1</vaadin-button>
  <vaadin-button>Button 2</vaadin-button>
  <vaadin-button>Button 3</vaadin-button>
</vaadin-vertical-layout>

Components in a Vertical Layout can be aligned vertically, as you’d expect. However and perhaps surprisingly, they can also be aligned horizontally in a Vertical Layout.

Vertical Alignment

You can position components at the top, middle, or bottom. You can also position them by specifying how the excess space in a layout is distributed among them.

Open in a
new tab
<vaadin-vertical-layout
  theme="spacing padding"
  style="justify-content: center"
>
  <vaadin-button>Button 1</vaadin-button>
  <vaadin-button>Button 2</vaadin-button>
  <vaadin-button>Button 3</vaadin-button>
</vaadin-vertical-layout>
Value Description

START (default)

Positions items at the top.

CENTER

Centers items, vertically.

END

Positions items at the bottom.

BETWEEN

Available space is distributed equally among items. However, no space is added before the first item, or after the last.

AROUND

Available space is distributed equally among items. However, the space before the first item and after the last is half of that between items.

EVENLY

Available space is distributed equally among items. The space before the first item and after the last item is the same as between others.

Horizontal Alignment

Components in a Vertical Layout are left-aligned by default, but can be centered, right-aligned or stretched horizontally.

Open in a
new tab
<vaadin-vertical-layout theme="spacing padding" style="align-items: center">
  <vaadin-button>Button 1</vaadin-button>
  <vaadin-button>Button 2</vaadin-button>
  <vaadin-button>Button 3</vaadin-button>
</vaadin-vertical-layout>
Value Description

START (default)

Left-aligns items for left-to-right language text (e.g., English). For right-to-left languages (e.g., Arabic, Hebrew), it right-aligns items.

CENTER

Centers items, horizontally.

END

Right-aligns for left-to-right language text. For right-to-left languages, it left-aligns items.

STRETCH

Stretches horizontally items with undefined width.

It’s also possible to align horizontally individual components by overriding the general alignment setting of the layout.

Open in a
new tab
<vaadin-vertical-layout theme="spacing padding" style="align-items: start">
  <vaadin-button style="align-self: end" theme="primary">Button 1</vaadin-button>
  <vaadin-button style="align-self: center"> Button 2</vaadin-button>
  <vaadin-button>Button 3</vaadin-button>
</vaadin-vertical-layout>

Spacing

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

Open in a
new tab
@state()
private theme = 'spacing';

protected override render() {
  return html`
    <vaadin-vertical-layout
      theme="${this.theme} padding"
      class="height-4xl"
      style="align-items: stretch"
    >
      <vaadin-button>Button 1</vaadin-button>
      <vaadin-button>Button 2</vaadin-button>
      <vaadin-button>Button 3</vaadin-button>
    </vaadin-vertical-layout>
    <vaadin-radio-group
      label="Spacing"
      .value="${this.theme}"
      @value-changed="${(event: RadioGroupValueChangedEvent) => {
        this.theme = event.detail.value;
      }}"
    >
      <vaadin-radio-button value="spacing" label="Enabled"></vaadin-radio-button>
      <vaadin-radio-button value="" label="Disabled"></vaadin-radio-button>
    </vaadin-radio-group>
  `;
}

Five different spacing theme variants are available:

Open in a
new tab
@state()
private themeVariant = 'spacing-xl';

protected override render() {
  return html`
    <vaadin-vertical-layout
      theme="${this.themeVariant} padding"
      class="height-4xl"
      style="align-items: stretch"
    >
      <vaadin-button>Button 1</vaadin-button>
      <vaadin-button>Button 2</vaadin-button>
      <vaadin-button>Button 3</vaadin-button>
    </vaadin-vertical-layout>
    <vaadin-radio-group
      label="Spacing variant"
      .value="${this.themeVariant}"
      @value-changed="${(event: RadioGroupValueChangedEvent) => {
        this.themeVariant = event.detail.value;
      }}"
    >
      <vaadin-radio-button value="spacing-xs" label="spacing-xs"></vaadin-radio-button>
      <vaadin-radio-button value="spacing-s" label="spacing-s"></vaadin-radio-button>
      <vaadin-radio-button value="spacing" label="spacing"></vaadin-radio-button>
      <vaadin-radio-button value="spacing-l" label="spacing-l"></vaadin-radio-button>
      <vaadin-radio-button value="spacing-xl" label="spacing-xl"></vaadin-radio-button>
    </vaadin-radio-group>
  `;
}
Theme Variant Usage Recommendation

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.

<vaadin-vertical-layout
  theme="spacing-xs padding">
</vaadin-vertical-layout>

Padding

Padding is the space allocated between the content in a layout and the outer border. This should not be confused with Margin, which is explained in the next section.

Padding can help distinguish the content in a layout from its surrounding. Padding is applied using the padding theme variant.

Open in a
new tab
@state()
private theme = 'padding';

protected override render() {
  return html`
    <vaadin-vertical-layout
      theme="${this.theme} spacing"
      class="height-4xl"
      style="align-items: stretch"
    >
      <vaadin-button>Button 1</vaadin-button>
      <vaadin-button>Button 2</vaadin-button>
      <vaadin-button>Button 3</vaadin-button>
    </vaadin-vertical-layout>
    <vaadin-radio-group
      label="Padding"
      .value="${this.theme}"
      @value-changed="${(event: RadioGroupValueChangedEvent) => {
        this.theme = event.detail.value;
      }}"
    >
      <vaadin-radio-button value="padding" label="Enabled"></vaadin-radio-button>
      <vaadin-radio-button value="" label="Disabled"></vaadin-radio-button>
    </vaadin-radio-group>
  `;
}

Margin

Margin is the space around a layout. This is different from Padding, which is explained in the previous section.

Open in a
new tab
@state()
private theme = 'margin';

protected override render() {
  return html`
    <div class="container">
      <vaadin-vertical-layout theme="${this.theme} spacing padding" style="align-items: stretch">
        <vaadin-button>Button 1</vaadin-button>
        <vaadin-button>Button 2</vaadin-button>
        <vaadin-button>Button 3</vaadin-button>
      </vaadin-vertical-layout>
    </div>
    <vaadin-radio-group
      label="Margin"
      .value="${this.theme}"
      @value-changed="${(event: RadioGroupValueChangedEvent) => {
        this.theme = event.detail.value;
      }}"
    >
      <vaadin-radio-button value="margin" label="Enabled"></vaadin-radio-button>
      <vaadin-radio-button value="" label="Disabled"></vaadin-radio-button>
    </vaadin-radio-group>
  `;
}

73cc0e40-d39a-11ed-afa1-0242ac120002