On this page

Overview

A list shows a set of similar things people scan, pick from, or open: providers to log in with, menu options, the devices in an area. Every row has the same structure, so the eye can run down the left edge and find what it needs.

A list is built from two parts. Pick the container by what the list means, then the row by what it does:

  • Containers: ha-list-base for a plain list, ha-list-selectable for a list people pick from, and ha-list-nav for a list of links.
  • Rows: ha-list-item-base for a row that only shows information, ha-list-item-button for a row that does something, and ha-list-item-option for a row people pick.

When to use

Use a list for:

  • A set of similar items that people scan, pick from, or open
  • Navigation to the next level, with a chevron at the end of each row
  • Rows that only show information, like a value or a message

Don't use a list for:

  • Actions on one item. Put them in a dropdown.
  • Picking one option from a few that need explaining. Use a select box.
  • Content that people show and hide. Use an expansion panel.

Anatomy

  1. List: the container. It has no padding of its own.
  2. Row: one item of the list
  3. Start: optional, an icon, image, or avatar at the start of the row
  4. Headline: the main text of the row
  5. Supporting text: optional, a short detail below the headline
  6. End: optional, content at the end, like a chevron, a short value, or a button

Variants

Rows

Start with the text, then add only what helps people recognize a row:

  • An icon at the start.
  • A supporting text, for a short detail, like a state or a description.
  • Something at the end, like a chevron when the row opens something, or a short value.
3

Rows that only show information

ha-list-item-base is a row that does nothing when selected, like a row that only shows a value or a message. It has no ripple and no keyboard focus. Set interactive to put it in the keyboard navigation of the list anyway, like for a row people can sort.

Rows that do something

ha-list-item-button opens something or runs an action. With an href, it renders a link, otherwise a button. The whole row is the target.

Lists people pick from

In ha-list-selectable, the rows are ha-list-item-option. The list owns the selection: people pick one option, or several with multi.

The default appearance, line, highlights the selected row. With appearance="checkbox", the row shows a checkbox, at the start or, with selection-position="end", at the end.

ha-list-nav wraps the list in a <nav> landmark, for a list of places people go to. Its rows are ha-list-item-button with an href. Give it a name with aria-label, so people can tell the landmarks of a page apart.

Behavior

  • Hover and pressed: a row that does something, or that people pick, shows a ripple.
  • Focus: one row at a time is in the tab order. The arrow keys move focus between the rows. The focused row gets an outline in the focus color and a light background.
  • Selected: in line appearance, the selected row gets a primary tint, and its text turns to the primary color. In checkbox appearance, the checkbox shows the state.
  • Disabled: the text turns to the disabled text color, and the row can't be selected or focused.
  • Long text: the headline and the supporting text are cut off with an ellipsis when they don't fit.
  • Focus outside the list: with virtual-focus, focus stays in another element, like the search field of a picker. The list marks the row the keyboard points at with active, and scrolls it into view.

Specs

Property Value Token
Row height, minimum 48px --ha-row-item-min-height
Padding top and bottom of a row 12px --ha-row-item-padding-block
Padding left and right of a row 16px --ha-row-item-padding-inline
Space between start, text, and end 16px --ha-row-item-gap
List padding 0 --ha-list-padding
Space between rows 0 --ha-list-gap
Headline font size 14px --ha-font-size-m
Supporting text font size 12px --ha-font-size-s
Supporting text color Secondary text color --secondary-text-color
Disabled text color #bdbdbd in the light theme, #6f6f6f in the dark theme --disabled-text-color
Focus outline 2px, in the focus color --ha-list-item-focus-width
Selected background, line appearance Primary tint --ha-list-item-selected-background

Guidelines

Do Keep the headline short, and put details in the supporting text.
Don't Put everything in a headline that gets cut off.

See UI text for how to write labels.

Accessibility

Keyboard

Key Action
Tab Moves focus into the list, to one row, and out of it again.
Arrow down and Arrow up Move focus to the next or previous row. With wrap-focus, focus wraps from the last row to the first, and back.
Home and End Move focus to the first or last row.
Page down and Page up Move focus a page down or up.
Enter or Space Activates the focused row, or picks the focused option.

Focus

One row at a time is in the tab order. The arrow keys move focus between the rows. Rows that only show information are skipped, unless they are interactive.

Target size

A row is at least 48px high, and as wide as the list.

Screen readers

  • ha-list-base has the role list, and its rows the role listitem.
  • ha-list-selectable has the role listbox, with aria-multiselectable when multi is set. Its options have the role option, and aria-selected.
  • ha-list-nav is a navigation landmark, with a list inside.
  • A disabled option has aria-disabled="true". A disabled link row sets aria-disabled="true" on its link, and a disabled button row uses a disabled native button. A plain ha-list-item-base row does not tell screen readers that it is disabled.

In the code

  • Give every list a name with aria-label, unless a visible heading already names it.
  • Use ha-list-item-option only in ha-list-selectable, and ha-list-item-button with an href for links.

In code

The elements are <ha-list-base>, <ha-list-selectable>, and <ha-list-nav>, with <ha-list-item-base>, <ha-list-item-button>, and <ha-list-item-option> rows.

HTML
<ha-list-base aria-label="Settings">
  <ha-list-item-button
    headline="Network"
    supporting-text="Connected over Wi-Fi"
  >
    <ha-svg-icon slot="start" path="..."></ha-svg-icon>
    <ha-icon-next slot="end"></ha-icon-next>
  </ha-list-item-button>
</ha-list-base>
HTML
<ha-list-selectable multi aria-label="Days">
  <ha-list-item-option
    appearance="checkbox"
    value="monday"
    headline="Monday"
  ></ha-list-item-option>
  <ha-list-item-option
    appearance="checkbox"
    value="tuesday"
    headline="Tuesday"
  ></ha-list-item-option>
</ha-list-selectable>

Attributes of ha-list-base

  • wrap-focus: the arrow keys wrap around at the ends.
  • virtual-focus: focus stays outside the list. The list marks the row the keyboard points at with active, instead of focusing it.
  • aria-label: the accessible name of the list.

Slots of ha-list-base

  • Default: the rows.

Events of ha-list-base

  • ha-list-activated: Enter or Space on the focused row. detail has the index and the item.

Methods of ha-list-base

  • moveActiveItem(): moves the active row to next, previous, first, last, next-page, or previous-page. Use it with virtual-focus.
  • getActiveItemIndex(): the index of the active row.
  • focusItemAtIndex(): focuses the row at an index.

Styling of ha-list-base

  • --ha-list-gap: the space between rows. Defaults to 0.
  • --ha-list-padding: the padding around the rows. Defaults to 0.

Attributes of ha-list-selectable

  • multi: people can pick more than one option.
  • controlled: a click only fires the events, and does not change selected. Set it when the selection comes from your own state.

ha-list-selectable also has the attributes of ha-list-base.

Events of ha-list-selectable

  • ha-list-item-selected: an option was picked. detail is the index of the option.
  • ha-list-item-deselected: an option was unpicked, with multi only. detail is the index of the option.

Methods of ha-list-selectable

  • clearSelection(): unpicks every option.

Attributes of ha-list-nav

  • aria-label: the name of the <nav> landmark.

Slots of ha-list-item-base

  • start: an icon, image, or avatar at the start.
  • end: content at the end, like a chevron, a value, or a button.
  • headline: the first line. Overrides the headline attribute.
  • supporting-text: the second line. Overrides the supporting-text attribute.
  • content: replaces the headline and the supporting text.

ha-list-item-button and ha-list-item-option have the same slots.

Attributes of ha-list-item-base

  • headline: the first line.
  • supporting-text: the second line.
  • disabled: disables the row.
  • interactive: puts the row in the keyboard navigation of the list, without an action.
  • active: set by a list with virtual-focus on the row the keyboard points at.

Styling of ha-list-item-base

  • --ha-row-item-min-height: the minimum height of a row. Defaults to 48px.
  • --ha-row-item-padding-block and --ha-row-item-padding-inline: the padding of a row. Default to 12px and 16px.
  • --ha-row-item-gap: the space between the start, the text, and the end. Defaults to 16px.
  • --ha-list-item-focus-background: the background on keyboard focus.
  • --ha-list-item-active-background: the background of the active row.
  • --ha-list-item-focus-radius, --ha-list-item-focus-width, --ha-list-item-focus-width-start, and --ha-list-item-focus-offset: the focus outline.

Attributes of ha-list-item-button

  • href: the row renders a link to this URL.
  • target, rel, and download: the attributes of the link, with href.

Attributes of ha-list-item-option

  • selected: the option is picked. Set by the list, or by you with controlled.
  • indeterminate: the checkbox shows a partly picked state, like for a group.
  • value: a value that identifies the option.
  • appearance: line highlights the selected row, checkbox shows a checkbox. Defaults to line.
  • selection-position: start or end, where the checkbox goes. Defaults to start.

Styling of ha-list-item-option

  • --ha-list-item-selected-background: the background of a selected option, in line appearance.

Source: src/components/list/ha-list-base.ts, src/components/list/ha-list-selectable.ts, src/components/list/ha-list-nav.ts, src/components/item/ha-list-item-base.ts, src/components/item/ha-list-item-button.ts, and src/components/item/ha-list-item-option.ts

Was this page helpful?

Last updated on .