Overview
A definition list shows pairs of a title and a value, such as the fields of a profile or the details of a service. The list is nds-definition-list, and each pair is an nds-definition-item. A title can start with an icon.
Pick another component when:
Markup
- Full name
- Mohammed Al-Harbi
- m.alharbi@example.gov.sa
- Organization
- Digital Services Department
- Position
- Senior Developer
Variants
The Layout, Style, Emphasis, Size and Loading rows go on the list. The two Cards rows are one choice: add both classes to every item. Title icons are optional: leave out the <i> for a list without them.
| Group | Option | Markup | On element | Use |
|---|---|---|---|---|
| Structure | Details (default) | — | — | dl, dt and dd, for data where each title names its value, such as a profile |
| Actions | Copy button | .nds-definition-action |
#dl-email |
Buttons after a value, such as copy and share. nds-definition-action on the dd puts the value and its buttons in one row. A button in it is SM, and a size class on the button still wins |
| Actions | Copy button | canon #dl-copy |
#dl-email |
The same: the button. Give it a data-copy with the value, or a data-copy-target, see Copy |
| Layout | Stacked (default) | — | — | Each value under its title, for long values |
| Layout | Table | .nds-table-view |
.nds-definition-list |
Titles in one column and values in the next, aligned across every item |
| Layout | Table on phones (hint: Below 600px only) | .nds-table-view-sm |
.nds-definition-list |
The table layout below 600px only. Stacked on wider screens |
| Layout | Table on tablets (hint: From 600px to 959px only) | .nds-table-view-md |
.nds-definition-list |
The table layout from 600px to 959px only. Stacked on other screens |
| Layout | Table on tablets and up (hint: From 600px up) | .nds-table-view-md |
.nds-definition-list |
The table layout from 600px up. Stacked on phones |
| Layout | Table on tablets and up (hint: From 600px up) | .nds-table-view-lg |
.nds-definition-list |
The same |
| Layout | Table on desktops (hint: From 960px up) | .nds-table-view-lg |
.nds-definition-list |
The table layout from 960px up. Stacked on smaller screens |
| Layout | Row (hint: Title and value on one line that wraps) | .nds-horizontal |
.nds-definition-list |
Each title and value on one row that wraps, with no shared columns. For compact card details |
| Grid | Grid | .nds-grid |
.nds-definition-list:not(.nds-table-view):not(.nds-table-view-sm):not(.nds-table-view-md):not(.nds-table-view-lg) |
Items in columns. --max-col, --mid-col and --min-col set the columns, see Grid |
| Style | Plain (default) | — | — | No lines between items |
| Style | Divided | .nds-divided |
.nds-definition-list |
A line between items. In a table layout, the lines span both columns. In a grid, they are the grid’s row lines |
| Style | Cards | .nds-card |
.nds-definition-item |
Each item in its own card |
| Style | Cards | .nds-stroke |
.nds-definition-item |
The same: gives each card its border |
| Emphasis | Highlight value | .nds-highlight-value |
.nds-definition-list |
The value bold, the title muted. For records the reader scans by value, such as a student’s status card |
| Size | MD (default) | — | — | A 24px icon, 16px text, MD buttons, SM tags, MD chips and the larger gap. A size class on a button, tag or chip still wins |
| Size | SM | .nds-sm |
.nds-definition-list |
A 20px icon, 14px text, SM buttons, XS tags, SM chips and a smaller gap |
| Loading | Loading | .nds-loading |
.nds-definition-list |
Gray bars in place of the titles and values while the data loads. The icons hide |
Built-in Features
-
Table View Layout
Two columns built on CSS subgrid, so titles and values line up across every item.
-
Responsive Table View
Turn the table layout on for phones, tablets or desktops only. Combine the classes to cover more than one screen range.
-
Divided Borders
Lines between items in every layout. With a responsive table view, the lines follow the layout on each screen size.
-
Grid Layout
Items in columns that change with the screen size, set with
--max-col,--mid-coland--min-col. -
CSS Custom Properties
Custom properties set the icon size, the gaps and the font sizes, so no style needs an override.
-
Automatic Icon Indent
In the stacked layout, a value lines up with its title's text when the title has an icon.
-
Loading Skeleton
Gray bars stand in for the titles and values before the page is ready, and while
nds-loadingis on.
Best Practices
- Use
dl,dtandddwhen each title names its value, such as a profile or the details of a service. Screen readers read them as pairs. - Keep the stacked layout when values are long or wrap to more lines.
- Use the table layout for short values side by side. For tablets and wider, add both
nds-table-view-mdandnds-table-view-lg. - Use the row layout for compact details inside a card.
- Give every title icon
aria-hidden="true". The label names the item. - A value that needs
dir="ltr", such as a time or a phone number, takes it on a<span>inside the<dd>, never on the<dd>. On the<dd>, it moves the value to the left edge of an Arabic page. - Keep the label inside an icon-only action button. Screen readers read it as the button’s name.
- In a divided list that is not a grid, add
nds-last-rowto the last item when another element comes after it in the list. Otherwise the item keeps the line under it.
API
Other Classes
| Class | Element | Effect |
|---|---|---|
nds-last-row |
.nds-definition-item |
Removes the line under the last divided item when another element comes after it in the list |
Data Attributes
| Attribute | Element | Effect |
|---|---|---|
data-state="loading" |
.nds-definition-list |
The same as nds-loading, for a script that already sets states. Use one of the two |
CSS Custom Properties
Set these on the list. nds-sm sets the icon size, the title and value sizes, the buttons, tags and chips, and the row gap. A value in the list’s style attribute wins over the size class.
| Property | Default | Controls |
|---|---|---|
--dl-icon-size |
24px |
Size of a title icon. nds-sm sets 20px. An icon never renders below 18px |
--dl-icon-gap |
8px |
Gap between a title icon and its label |
--dl-title-FS |
var(--typo-text-md-FS) |
Title font size. nds-sm sets --typo-text-sm-FS |
--dl-title-LH |
var(--typo-text-md-LH) |
Title line height. nds-sm sets --typo-text-sm-LH. Set it with a custom --dl-title-FS |
--dl-desc-FS |
var(--typo-text-md-FS) |
Value font size. nds-sm sets --typo-text-sm-FS |
--dl-desc-LH |
var(--typo-text-md-LH) |
Value line height. nds-sm sets --typo-text-sm-LH. Set it with a custom --dl-desc-FS |
--row-gap |
var(--spacing-xl) |
Gap between items, and on each side of a divider in a stacked list. A divided table uses 8px. nds-sm sets --spacing-lg |
--col-gap |
var(--spacing-xl) |
Gap between a title and its value in the table layout. The row layout uses var(--spacing-sm) |
--gap |
— | Sets both gaps when --row-gap and --col-gap are not set |
Tokens
It reads these shared tokens. A change to one also changes other components: see Tokens.
Source: the var() reads in _sass/components/_definition-list.scss.
| Token | Preview | Value |
|---|---|---|
--text-primary-paragraphRead by color | var(--colors-neutral-700)Dark mode var(--colors-neutral-300) | |
--text-secondary-paragraphRead by color | var(--colors-neutral-500)Dark mode var(--colors-neutral-400) | |
--divider-colorRead by border-bottom | var(--colors-alpha-black-10)Dark mode var(--colors-alpha-white-10) | |
--icon-primaryRead by color | var(--colors-primary-600)Dark mode var(--colors-primary-400) |