Overview
A breadcrumb is a <nav> that holds an ordered list: one item per level, from Home to the current page. A script collapses a long trail behind a More button.
Pick another component when:
- the links are the site’s navigation: Main Navigation or Side Menu
- the links move between the steps of one task: Stepper
- the links switch views on one page: Tabs
Markup
<nav class="nds-breadcrumb-nav" aria-label="Breadcrumb" data-i18n-aria-label="breadcrumb.breadcrumb">
<ol class="nds-breadcrumb">
<li><a href="#">Home</a></li>
<li><a href="#">Services</a></li>
<li aria-current="page">Register a new commercial establishment and issue its first license</li>
</ol>
</nav>
Variants
li:last-child is the current page item.
| Group | Option | Markup | On element | Use |
|---|---|---|---|---|
| Structure | Standard (default) | — | — | Three levels: Home, a parent page and the current page |
| Structure | Short trail | canon #breadcrumb-two-levels |
— | Two levels: Home and the current page, for a page one step below Home |
| Structure | Deep trail | canon #breadcrumb-deep |
— | Seven levels. The script shows the first level, a More button and the last two |
| Truncate | Truncate (hint: Cuts a long page title with an ellipsis) | .nds-truncate |
li:last-child |
Cuts a long current page title with an ellipsis, so the trail stays on one line |
| Loading | Loading | .nds-loading |
.nds-breadcrumb-nav |
Shows each label as a pulsing skeleton bar while the trail content loads. Remove it when the content is ready |
Built-in Features
-
Auto-initialization
The script sets up every
.nds-breadcrumb-navwhen the page loads. It needs no call. -
Automatic Collapse
A trail of more than 5 levels shows the first level, a More button and the last two. The button opens a menu of the hidden levels.
-
Keyboard Support
The More menu is a Dropmenu, so it opens, moves between items and closes with the keyboard.
-
Stable Layout
Until the script runs, each label shows as a skeleton bar. A long trail already takes its collapsed size, so the page does not shift when it collapses.
-
Neutral Links
The links use the neutral link colors, so the trail stays quieter than the page content. Add
nds-primaryto one link that must stand out.
Best Practices
- Show a breadcrumb on every page below Home. Leave it off the home page.
- Start the trail with Home.
- End the trail with the current page as plain text in
<li aria-current="page">. Do not make it a link. - Keep
aria-labelon the<nav>, so screen readers can name the landmark. - Write every level in the markup. Do not hide levels yourself: the script collapses the trail.
- Make each middle level a plain
<a>with text. The More menu copies only the link address and its text. - Keep the text of each level short, so the trail reads at a glance.
- Add
nds-truncateto the current item when page titles can be long. The title then stops at about 45 characters.
API
Other Classes
| Class | Element | Effect |
|---|---|---|
nds-breadcrumb-ellipsis |
<li> |
The script adds this item to a collapsed trail. It holds the More button and its menu |
nds-breadcrumb-menu |
.nds-dropmenu-menu |
The script adds it to the More menu. Style the menu with this class: it still matches when the menu moves to <body> |
Data Attributes
| Attribute | Element | Effect |
|---|---|---|
data-state="loading" |
.nds-breadcrumb-nav |
The same as nds-loading |
Tokens
It reads these shared tokens. A change to one also changes other components: see Tokens.
Source: the var() reads in _sass/components/_breadcrumb.scss.
| Token | Preview | Value |
|---|---|---|
--text-secondary-paragraphRead by color | var(--colors-neutral-500)Dark mode var(--colors-neutral-400) | |
--icon-separatorRead by background | var(--colors-neutral-400)Dark mode var(--colors-neutral-500) |
JavaScript
The NDS.Breadcrumb script loads after the page shows. Until it loads, each call loads it and returns a promise of the result, so await a call whose result you use.
The instance is on the .nds-breadcrumb-nav as ndsBreadcrumb. It is there once the component starts: code that runs at page load waits for NDS.init.ready.
| Method | Effect |
|---|---|
NDS.Breadcrumb.init() |
Sets up every .nds-breadcrumb-nav that is not set up yet, and stores its instance in nav.ndsBreadcrumb. It runs on page load. Call it after you add a breadcrumb to the page |
NDS.Breadcrumb.create(nav) |
Sets up one breadcrumb and returns its instance. Returns the running one when nav already has one, and null when it has no items |
NDS.Breadcrumb.destroy(nav) |
The same as instance.destroy() |
instance.destroy() |
Removes the More menu and puts every level back |
Destroy a trail before you change its list, then call init():
const nav = document.querySelector('.nds-breadcrumb-nav');
nav.ndsBreadcrumb?.destroy();
nav.querySelector('.nds-breadcrumb').innerHTML =
'<li><a href="/">Home</a></li><li aria-current="page">Services</li>';
NDS.Breadcrumb.init();
The full API is in the banner of _js/nds-breadcrumb.js.
Related
- Hero: the sub hero holds the page’s breadcrumb above the title, with a truncated current item.
- Service Template: a template page whose breadcrumb shows its parent section.