Checkbox

Checkbox is an input field representing a binary choice. Checkbox Group is a group of related binary choices.

Open in a
new tab
<vaadin-checkbox>I accept the terms and conditions</vaadin-checkbox>
Open in a
new tab
<vaadin-checkbox-group
  label="Export data"
  .value="${this.value}"
  @value-changed="${(e: CustomEvent) => (this.value = e.detail.value)}"
  theme="vertical"
>
  <vaadin-checkbox value="0">Order ID</vaadin-checkbox>
  <vaadin-checkbox value="1">Product name</vaadin-checkbox>
  <vaadin-checkbox value="2">Customer</vaadin-checkbox>
  <vaadin-checkbox value="3">Status</vaadin-checkbox>
</vaadin-checkbox-group>

Use Checkbox Group to group related items. Individual checkboxes should be used for options that are not related to each other in any way.

Common Input Field Features

Checkbox Group includes all shared input field features.

States

Disabled

Disable a field to mark it as currently unavailable. Disabled state is used for fields that are not editable and do not need to be readable. Disabled elements cannot be focused and may be inaccessible to assistive technologies like screen readers.

Disabling can be preferable to hiding an element to prevent changes in layout when the element’s visibility changes, and to make users aware of its existence even when currently unavailable.

Open in a
new tab
<vaadin-checkbox-group label="Departments" theme="vertical" disabled>
  <vaadin-checkbox value="engineering">Engineering</vaadin-checkbox>
  <vaadin-checkbox value="human-resources">Human Resources</vaadin-checkbox>
  <vaadin-checkbox value="marketing">Marketing</vaadin-checkbox>
  <vaadin-checkbox value="operations">Operations</vaadin-checkbox>
  <vaadin-checkbox value="sales">Sales</vaadin-checkbox>
</vaadin-checkbox-group>
Note
Read-only state
Checkbox does not support read-only state.

Indeterminate

The indeterminate state can be used for a parent checkbox to show that there is a mix of checked and unchecked child items in a list, and to change the state of all child items at once.

Open in a
new tab
<vaadin-checkbox
  .checked="${this.selectedIds.length === this.items.length}"
  .indeterminate="${this.selectedIds.length > 0 &&
  this.selectedIds.length < this.items.length}"
  @change="${(e: Event) =>
    (this.selectedIds = (e.target as CheckboxElement).checked
      ? this.items.map((person) => String(person.id))
      : [])}"
>
  Notify users
</vaadin-checkbox>

<vaadin-checkbox-group
  label="Users to notify"
  theme="vertical"
  .value="${this.selectedIds}"
  @value-changed="${(e: CustomEvent) => (this.selectedIds = e.detail.value)}"
>
  ${this.items.map((person) => {
    return html`
      <vaadin-checkbox .value="${String(person.id)}">
        ${person.firstName} ${person.lastName}
      </vaadin-checkbox>
    `;
  })}
</vaadin-checkbox-group>

Orientation

The component’s default orientation is horizontal but vertical orientation is recommended whenever possible as it’s easier for the user to scan a vertical list of options:

Open in a
new tab
<vaadin-checkbox-group label="Working days" theme="vertical">
  <vaadin-checkbox value="mon">Monday</vaadin-checkbox>
  <vaadin-checkbox value="tue">Tuesday</vaadin-checkbox>
  <vaadin-checkbox value="wed">Wednesday</vaadin-checkbox>
  <vaadin-checkbox value="thu">Thursday</vaadin-checkbox>
  <vaadin-checkbox value="fri">Friday</vaadin-checkbox>
  <vaadin-checkbox value="sat">Saturday</vaadin-checkbox>
  <vaadin-checkbox value="sun">Sunday</vaadin-checkbox>
</vaadin-checkbox-group>

In cases where vertical space needs to be conserved, horizontal orientation can be used, but no more than 3 options are recommended:

Open in a
new tab
<vaadin-checkbox-group label="Permissions">
  <vaadin-checkbox value="read">Read</vaadin-checkbox>
  <vaadin-checkbox value="edit">Edit</vaadin-checkbox>
  <vaadin-checkbox value="delete">Delete</vaadin-checkbox>
</vaadin-checkbox-group>

Best Practices

Labeling

Aim for short and descriptive labels using positive wording. Avoid negations.

Open in a
new tab
@customElement('checkbox-labeling')
export class Example extends LitElement {
  protected createRenderRoot() {
    const root = super.createRenderRoot();
    // Apply custom theme (only supported if your app uses one)
    applyTheme(root);
    return root;
  }

  render() {
    return html`<vaadin-checkbox>Yes, I agree</vaadin-checkbox>`;
  }
}

It is important to provide labels for Checkbox Groups to clearly distinguish adjacent groups.

Open in a
new tab
<vaadin-vertical-layout>
  <vaadin-checkbox-group label="Manufacturer" theme="vertical">
    <vaadin-checkbox value="0">Akuchi</vaadin-checkbox>
    <vaadin-checkbox value="1">Broek</vaadin-checkbox>
    <vaadin-checkbox value="2">Wulf</vaadin-checkbox>
  </vaadin-checkbox-group>

  <vaadin-checkbox-group label="Status" theme="vertical">
    <vaadin-checkbox value="0">In progress</vaadin-checkbox>
    <vaadin-checkbox value="1">Done</vaadin-checkbox>
    <vaadin-checkbox value="2">Cancelled</vaadin-checkbox>
  </vaadin-checkbox-group>
</vaadin-vertical-layout>
ComponentUsage recommendations

Select

A field for selecting an item from a list of options which are presented in an overlay. Recommended when there is insufficient space for a Radio Button Group.

Combo Box

A filterable, lazy loading alternative to Select, recommended for ten or more items.

List Box

Scrollable list of options. Supports single and multi-select.

Radio Button Group

Corresponding component for mutually exclusive options, or “single-select”.