List
A list shows a set of rows, each with a line of text and optionally an icon, a second line, and something at the end.
Network Connected over Wi-Fi
Location Home
System Updates, backups, and logs
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.
ha-list and ha-list-item are the older lists, built on Material Web Components. The frontend is moving to a newer list family: ha-list-base, ha-list-item-base, ha-list-item-button, ha-list-selectable, and ha-list-nav. Many lists in the frontend already use it. For new code, use the new family: see the new list family at the end of this page. Most of this page covers the older list, since a good number of screens still use it.
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.
- List: the container, with 8px of padding at the top and bottom
- Row: one item of the list
- Graphic: optional, an icon, avatar, or control at the start of the row
- First line: the main text of the row
- Second line: optional, a short detail below the first line
- Meta: optional, content at the end, like a chevron or a short value
Start with the text, then add only what helps people recognize a row:
- An icon at the start.
- A second line, 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.
Two lines With a second line of detail
With an icon
With something at the end 3
A row reserves room at the start for its graphic, in one of these sizes: an icon, an avatar (a round image), a medium or large image, or a control like a checkbox.
A row that does nothing when selected, like a row that only shows a value or a message, can be made non-interactive. It then has no ripple and no keyboard focus.
- Hover and pressed: an interactive row shows a ripple. It is black unless the theme sets another color. The dark theme sets it to a light gray. An activated row uses the primary color for its ripple.
- Focus: one row at a time is in the tab order. Arrow keys move focus between the rows.
- Activated: in a list where a row can be activated, the selected row gets a primary tint at 12% opacity, and its graphic turns to the primary color.
- Disabled: the text turns to the disabled text color, and the row can't be selected.
- Long text: the first line is cut off with an ellipsis when it doesn't fit. The second line is cut off too, unless the row lets it wrap. Then the row grows with it.
| Property | Value | Token |
|---|---|---|
| Row height, one line | 48px | None |
| Row height, one line with an icon or avatar | 48px | None |
| Row height, two lines | 72px | None |
| Row height, one line with a medium or large graphic | 72px | None |
| Padding left and right | 20px | --mdc-list-side-padding |
| List padding top and bottom | 8px | --mdc-list-vertical-padding |
| Icon size | 24px | --mdc-list-item-graphic-size |
| Avatar size | 40px | --mdc-list-item-graphic-size |
| Medium and large graphic size | 56px | --mdc-list-item-graphic-size |
| Space between icon and text, one line | 20px | --mdc-list-item-graphic-margin |
| Space between icon and text, two lines | 32px | --mdc-list-item-graphic-margin |
| Meta size | 24px | --mdc-list-item-meta-size |
| First line font size | 1rem | --mdc-typography-subtitle1-font-size |
| Second line font size | 0.875rem | --mdc-typography-body2-font-size |
| Disabled text color | #bdbdbd in the light theme, #6f6f6f in the dark theme |
--disabled-text-color |
| Activated tint | 12% opacity | --mdc-ripple-activated-opacity |
See UI text for how to write labels.
| 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. A list can let focus wrap from the last row to the first, and back. |
| Home and End | Move focus to the first or last row. |
| Enter or Space | Activates the focused row. |
One row at a time is in the tab order. Arrow keys move focus between the rows.
A row is at least 48px high, and as wide as the list.
By default, a screen reader gets no list structure: the list and its rows have no role, so it hears the text of the rows. Disabled rows are announced as disabled. The list can get a role and a name in code, see below.
- The list and its rows have no role by default. Set
innerRoleon the list anditemRolesfor the rows, likelistboxandoption, andinnerAriaLabelfor the name of the list. - A disabled row has
aria-disabled="true". - With the role
option, a selected row hasaria-selected="true". - A row with
noninteractivecan't take focus.
- Dropdown: a menu of actions
- Select box: picking one option from a few
- Expansion panel: content that people show and hide
The element is <ha-list>, with <ha-list-item> rows. Both extend the Material Web Components list.
<ha-list>
<ha-list-item graphic="icon" twoline hasMeta>
<ha-svg-icon slot="graphic" path="..."></ha-svg-icon>
Network
<span slot="secondary">Connected over Wi-Fi</span>
<ha-svg-icon slot="meta" path="..."></ha-svg-icon>
</ha-list-item>
</ha-list>Attribute names are case-insensitive in HTML, so hasMeta and hasmeta are the same.
activatable: shows the selected row as activated.multi: allows selecting more than one row.wrapFocus: arrow keys wrap from the last row to the first, and back.rootTabbable: makes the list itself focusable, instead of the first row.noninteractive: turns off selection and keyboard navigation for the whole list.innerRoleandinnerAriaLabel: the role and the accessible name of the inner list element.itemRoles: the role given to every row, likeoption.
graphic: reserves room for content in thegraphicslot.icon,avatar,medium,large, orcontrol.twoline: shows thesecondaryslot as a second line.multiline-secondary: lets the second line wrap, instead of cutting it off.hasMeta: shows themetaslot at the end.noninteractive: the row can't be selected or focused.disabled: disables the row.selectedandactivated: the selection state.value: a value that identifies the row.
- Default: the first line of text.
secondary: the second line, whentwolineis set.graphic: an icon, avatar, or control at the start, whengraphicis set.meta: content at the end, whenhasMetais set.
actiononha-list: a row was activated.detail.indexis the index of the row.selectedonha-list: the selection changed.detail.indexis the selected index, or a set of indexes withmulti.request-selectedonha-list-item: the row asks to be selected or deselected.detail.selectedis the new state, anddetail.sourcesays whether it came from aninteractionor apropertychange.
--mdc-list-side-padding: the padding on both sides of a row. Defaults to20px.--mdc-list-side-padding-leftand--mdc-list-side-padding-right: the padding of one side.--mdc-list-item-graphic-margin: the space between the graphic and the text.--mdc-list-item-meta-display: the display of the meta slot.
Source: src/components/ha-list.ts and src/components/ha-list-item.ts
The new lists are accessible and keyboard friendly from the start. Pick the container by what the list means, then the item by what a row does. They are not part of the live components on this site yet, so there is no demo.
<ha-list-base>: a plain list, with the rolelist. The arrow keys move focus between rows, Home and End jump to the first and last enabled row, Page up and Page down move a page, and Enter or Space activates the focused row. Only one row is in the tab order at a time.<ha-list-selectable>: a list people pick from, with the rolelistbox. Its rows are<ha-list-item-option>. Setmultito allow picking more than one.<ha-list-nav>: a list of links, wrapped in a<nav>landmark. Its rows are<ha-list-item-button>with anhref. Name the landmark witharia-label.
Attributes of the containers:
wrap-focus: the arrow keys wrap around at the ends.virtual-focus: focus stays outside the list, like in the search field of a picker. The list marks the row the keyboard points at withactive, and scrolls it into view. The element that has focus moves it withmoveActiveItem().aria-label: the accessible name.multi: onha-list-selectableonly, allows picking more than one option.
Events:
ha-list-activated: Enter or Space on a focused row.detailhas theindexand theitem.ha-list-item-selectedandha-list-item-deselected: onha-list-selectable, an option was picked or unpicked.detailis the index of the option. Deselected only fires withmulti.
Styling: --ha-list-gap sets the space between rows, --ha-list-padding the padding around the list. Both default to 0.
Every item has the same row layout, with these slots and attributes:
start: the leading part, like an icon or an avatar.end: the trailing part, like a value or a chevron.headlineandsupporting-text: the first and second line, as an attribute or a slot.content: replaces the whole middle part.disabled: dims the row and blocks the pointer.
The items:
<ha-list-item-base>: a row that only shows information, with the rolelistitem. Setinteractiveto put it in the keyboard navigation of the list without an action, like a row people can sort.<ha-list-item-button>: a row that does something. It renders a link when it has anhref, and a button otherwise. The whole row is the target.<ha-list-item-option>: a row people can pick, with the roleoptionandaria-selected. The list owns the selection. Withappearance="checkbox"it shows a checkbox, at thestartor theendwithselection-position. The default appearance,line, highlights the selected row.
Styling of the rows:
--ha-row-item-min-height: the minimum height of a row. Defaults to48px.--ha-row-item-padding-block,--ha-row-item-padding-inline, and--ha-row-item-gap: the padding of a row, and the space between its parts.--ha-list-item-focus-backgroundand--ha-list-item-active-background: the background on keyboard focus, and of theactiverow.--ha-list-item-selected-background: the background of a selected option, withappearance="line".
Source: src/components/list/ and src/components/item/