Navigation
Breadcrumb
The trail of links to the current page, as an ordered list in a navigation landmark. Separators are yours to add.
- Element
<slab-breadcrumb>- Built on
<nav> + <ol>
Example
Here's a styled version, <slab-styled-breadcrumb>. It's not
in the package — it's an example of what you can build with the
headless element. Copy it and make it yours at the
bottom of this page. Switch to "As it ships" to see the same markup
with the headless element and no CSS at all. That's your starting
point.
<slab-styled-breadcrumb>
<a href="#jobs">Jobs</a>
<a href="#alder">14 Alder Lane</a>
<a href="#foundation">Foundation</a>
</slab-styled-breadcrumb>
<slab-breadcrumb>
<a href="#jobs">Jobs</a>
<a href="#alder">14 Alder Lane</a>
<a href="#foundation">Foundation</a>
</slab-breadcrumb>
Usage
pnpm add slab-elements lit
import 'slab-elements/breadcrumb.js';
export function MyBreadcrumb() {
return (
<slab-breadcrumb>
<a href="/">Home</a>
<a href="/docs/">Docs</a>
<a href="/docs/install/">Install</a>
</slab-breadcrumb>
);
}
MyBreadcrumb.jsx React 19 or later, which sets props on custom elements as properties.
import 'slab-elements/breadcrumb.js';
import { html, LitElement } from 'lit';
import { customElement } from 'lit/decorators.js';
@customElement('my-breadcrumb')
export class MyBreadcrumb extends LitElement {
render() {
return html`
<slab-breadcrumb>
<a href="/">Home</a>
<a href="/docs/">Docs</a>
<a href="/docs/install/">Install</a>
</slab-breadcrumb>
`;
}
}
my-breadcrumb.ts Slab is built on Lit, so its elements are at home in Lit's templates.
<script setup>
import 'slab-elements/breadcrumb.js';
</script>
<template>
<slab-breadcrumb>
<a href="/">Home</a>
<a href="/docs/">Docs</a>
<a href="/docs/install/">Install</a>
</slab-breadcrumb>
</template>
MyBreadcrumb.vue Let Vue's compiler know slab- tags are custom elements with isCustomElement.
<script>
import 'slab-elements/breadcrumb.js';
</script>
<slab-breadcrumb>
<a href="/">Home</a>
<a href="/docs/">Docs</a>
<a href="/docs/install/">Install</a>
</slab-breadcrumb>
MyBreadcrumb.svelte Svelte binds properties and events to custom elements like any other element.
import 'slab-elements/breadcrumb.js';
export const MyBreadcrumb = <template>
<slab-breadcrumb>
<a href="/">Home</a>
<a href="/docs/">Docs</a>
<a href="/docs/install/">Install</a>
</slab-breadcrumb>
</template>;
MyBreadcrumb.gjs Ember sets attributes, and a dynamic value like {{this.max}} sets the property when the element has one. {{on}} listens for any event by its name.
<script type="module">
import 'slab-elements/breadcrumb.js';
</script>
<slab-breadcrumb>
<a href="/">Home</a>
<a href="/docs/">Docs</a>
<a href="/docs/install/">Install</a>
</slab-breadcrumb>
index.html Any bundler (or an import map) takes care of the imports.
Behavior
A breadcrumb with no visual styles: a <nav> around an <ol> of the links slotted into it, the last of which is the current page.
An <ol> may only hold <li>s, so each slotted element gets an <li> of its own: it's put in a slot inside one, through the slot attribute, which Breadcrumb sets. The last element gets aria-current="page" unless it has an aria-current already.
Separators are a design's, so there are none. Each <li> is ::part(item), and every one but the first starts with a ::part(separator), which is hidden from screenreaders and has no content until you give it some. The <ol> keeps its numbers and indent until your styles take them off.
API
<slab-breadcrumb>
| Name | Type | Default | Description |
|---|---|---|---|
label
|
string |
Names the navigation. "Breadcrumb" in English when unset. |
| Name | Type | Description |
|---|---|---|
items
Read-only
|
Element[] |
The slotted links, in order. |
| Name | Type | Description |
|---|---|---|
(default)
|
Element |
The links, from the first page to the current one |
| Name | Description |
|---|---|
item
|
Each link's list item |
list
|
The links |
nav
|
The navigation |
separator
|
What sits between two links, before every one but the first |
Copy and own it
<slab-styled-breadcrumb> isn't in the package. It's an example —
copy it into your project and change whatever you want. Keyboard,
focus, ARIA, forms, and events all come from the headless element,
and the styles only reach in through ::part() and
:state(), same as yours would.
The same styles, written from outside the element, so
there's nothing to subclass. The CSS styles every
<slab-breadcrumb> on the page. Import
tokens.css, the colors and fonts every styled
example shares, once, wherever your global styles go.
Each component registers its headless element and imports its CSS. Use it like the element: its props are the element's attributes and properties.
Breadcrumb.jsx
import 'slab-elements/breadcrumb.js';
import './breadcrumb.css';
export function Breadcrumb(props) {
return <slab-breadcrumb {...props} />;
}
breadcrumb.css
slab-breadcrumb::part(list) {
align-items: center;
display: flex;
flex-wrap: wrap;
font-family: var(--font-display);
font-size: 1.0625rem;
gap: 0.5rem;
list-style: none;
margin: 0;
padding: 0;
}
slab-breadcrumb::part(item) {
align-items: center;
display: flex;
gap: 0.5rem;
}
slab-breadcrumb::part(separator)::before {
color: var(--ember);
content: '/';
font-weight: 700;
}
slab-breadcrumb > a {
color: var(--ink);
text-decoration-color: var(--ember);
text-decoration-line: underline;
text-decoration-thickness: 2px;
text-underline-offset: 0.25em;
}
slab-breadcrumb > a:hover {
background-color: var(--ink);
color: var(--paper);
text-decoration-line: none;
}
slab-breadcrumb > a:focus-visible {
outline: 3px solid var(--ember);
outline-offset: 2px;
}
slab-breadcrumb > [aria-current='page'] {
font-weight: 700;
text-decoration-line: none;
}
tokens.css
:root {
/* Secondary text. 6.8:1 and 6.9:1 on paper. */
--ash: var(--slab-styled-ash, light-dark(#5e5a55, #a8a19a));
--border: 2px solid var(--ink);
/* Behind disabled and read-only controls, and hovered rows. */
--chalk: var(--slab-styled-chalk, light-dark(#f4f1ec, #2b2926));
/*
The logo's orange, brighter in the dark. 4.25:1 and 5.2:1 on paper is
enough for borders, fills and large text, but not always for small text,
which takes "--ember-deep".
*/
--ember: var(--slab-styled-ember, light-dark(#d9492a, #ec5f3b));
/*
Orange for small text on paper, and for paper text on it. 5.7:1 and
7.4:1.
*/
--ember-deep: var(--slab-styled-ember-deep, light-dark(#b3381a, #ff8566));
--font-body: var(
--slab-styled-font-body,
'IBM Plex Sans',
system-ui,
sans-serif
);
--font-display: var(
--slab-styled-font-display,
'Zilla Slab',
rockwell,
'Roboto Slab',
serif
);
--font-mono: var(
--slab-styled-font-mono,
'IBM Plex Mono',
ui-monospace,
monospace
);
--ink: var(--slab-styled-ink, light-dark(#1c1c1c, #f4f1ec));
--paper: var(--slab-styled-paper, light-dark(#fff, #1a1918));
/* The hard, offset shadow a raised surface casts. */
--shadow: 4px 4px 0 var(--ink);
}
/*
Forced colors, such as Windows' contrast themes, replace every color that
isn't a system color, so ember fills and paper marks all become the same
background, and a checked Checkbox looks like an unchecked one. The palette
becomes the user's system colors instead, which are kept. Ember is the
highlight, the color of what's selected, and ember-deep, being for text and
for paper text on it, is the text color.
*/
@media (forced-colors: active) {
:host {
--ash: GrayText;
--chalk: Canvas;
--ember: Highlight;
--ember-deep: CanvasText;
--ink: CanvasText;
--paper: Canvas;
}
}
Under the hood, it's just the headless element, subclassed,
with styles set. That's it. To use it, copy
these files, swap the tag in @customElement()
for one of your own, and import it.
tokens.styles.ts holds the colors and fonts
every styled example shares, so you only need it once.
breadcrumb.ts
import { customElement } from 'lit/decorators.js';
import Breadcrumb from 'slab-elements/breadcrumb.js';
import styles from './breadcrumb.styles.js';
import tokens from './tokens.styles.js';
declare global {
interface HTMLElementTagNameMap {
'slab-styled-breadcrumb': StyledBreadcrumb;
}
}
/**
* Breadcrumb, styled: slab-serif links underlined in ember, divided by ember
* slashes, with the current page in bold.
*/
@customElement('slab-styled-breadcrumb')
export default class StyledBreadcrumb extends Breadcrumb {
static override styles = [tokens, styles];
}
breadcrumb.styles.ts
import { css } from 'lit';
/*
The links are the consumer's own, slotted in, so they're styled through
"::slotted()". Breadcrumb marks the last one with "aria-current".
*/
export default css`
[part~='list'] {
align-items: center;
display: flex;
flex-wrap: wrap;
font-family: var(--font-display);
font-size: 1.0625rem;
gap: 0.5rem;
list-style: none;
margin: 0;
padding: 0;
}
[part~='item'] {
align-items: center;
display: flex;
gap: 0.5rem;
}
[part~='separator']::before {
color: var(--ember);
content: '/';
font-weight: 700;
}
::slotted(a) {
color: var(--ink);
text-decoration-color: var(--ember);
text-decoration-line: underline;
text-decoration-thickness: 2px;
text-underline-offset: 0.25em;
}
::slotted(a:hover) {
background-color: var(--ink);
color: var(--paper);
text-decoration-line: none;
}
::slotted(a:focus-visible) {
outline: 3px solid var(--ember);
outline-offset: 2px;
}
::slotted([aria-current='page']) {
font-weight: 700;
text-decoration-line: none;
}
`;
tokens.styles.ts
import { css } from 'lit';
/*
The styled components' palette and type, taken from the logo: ink for the
courses, ember for the base, paper behind them.
Each is a short alias for a "--slab-styled-*" property, with the default as
its fallback. Retheming is "--slab-styled-ember" and the rest on ":root",
which every shadow root inherits. Were the defaults declared under those
names here instead, each host's own declaration would shadow the page's.
Each default is "light-dark()", so the components follow the page's
"color-scheme": "dark" for dark, "light" for light, and "light dark" to
follow the operating system. Ink and paper trade places in the dark, so
ink is always the text and paper always what's behind it. Contrast is given
as light, then dark.
*/
export default css`
:host {
/* Secondary text. 6.8:1 and 6.9:1 on paper. */
--ash: var(--slab-styled-ash, light-dark(#5e5a55, #a8a19a));
--border: 2px solid var(--ink);
/* Behind disabled and read-only controls, and hovered rows. */
--chalk: var(--slab-styled-chalk, light-dark(#f4f1ec, #2b2926));
/*
The logo's orange, brighter in the dark. 4.25:1 and 5.2:1 on paper is
enough for borders, fills and large text, but not always for small text,
which takes "--ember-deep".
*/
--ember: var(--slab-styled-ember, light-dark(#d9492a, #ec5f3b));
/*
Orange for small text on paper, and for paper text on it. 5.7:1 and
7.4:1.
*/
--ember-deep: var(--slab-styled-ember-deep, light-dark(#b3381a, #ff8566));
--font-body: var(
--slab-styled-font-body,
'IBM Plex Sans',
system-ui,
sans-serif
);
--font-display: var(
--slab-styled-font-display,
'Zilla Slab',
rockwell,
'Roboto Slab',
serif
);
--font-mono: var(
--slab-styled-font-mono,
'IBM Plex Mono',
ui-monospace,
monospace
);
--ink: var(--slab-styled-ink, light-dark(#1c1c1c, #f4f1ec));
--paper: var(--slab-styled-paper, light-dark(#fff, #1a1918));
/* The hard, offset shadow a raised surface casts. */
--shadow: 4px 4px 0 var(--ink);
}
/*
Forced colors, such as Windows' contrast themes, replace every color that
isn't a system color, so ember fills and paper marks all become the same
background, and a checked Checkbox looks like an unchecked one. The palette
becomes the user's system colors instead, which are kept. Ember is the
highlight, the color of what's selected, and ember-deep, being for text and
for paper text on it, is the text color.
*/
@media (forced-colors: active) {
:host {
--ash: GrayText;
--chalk: Canvas;
--ember: Highlight;
--ember-deep: CanvasText;
--ink: CanvasText;
--paper: Canvas;
}
}
`;
The same styles, written from outside the element, so
there's nothing to subclass. The CSS styles every
<slab-breadcrumb> on the page. Import
tokens.css, the colors and fonts every styled
example shares, once, wherever your global styles go.
Each component registers its headless element and imports its CSS. Use it like the element: its props are the element's attributes and properties.
Breadcrumb.vue
<script setup>
import 'slab-elements/breadcrumb.js';
import './breadcrumb.css';
</script>
<template>
<slab-breadcrumb><slot /></slab-breadcrumb>
</template>
breadcrumb.css
slab-breadcrumb::part(list) {
align-items: center;
display: flex;
flex-wrap: wrap;
font-family: var(--font-display);
font-size: 1.0625rem;
gap: 0.5rem;
list-style: none;
margin: 0;
padding: 0;
}
slab-breadcrumb::part(item) {
align-items: center;
display: flex;
gap: 0.5rem;
}
slab-breadcrumb::part(separator)::before {
color: var(--ember);
content: '/';
font-weight: 700;
}
slab-breadcrumb > a {
color: var(--ink);
text-decoration-color: var(--ember);
text-decoration-line: underline;
text-decoration-thickness: 2px;
text-underline-offset: 0.25em;
}
slab-breadcrumb > a:hover {
background-color: var(--ink);
color: var(--paper);
text-decoration-line: none;
}
slab-breadcrumb > a:focus-visible {
outline: 3px solid var(--ember);
outline-offset: 2px;
}
slab-breadcrumb > [aria-current='page'] {
font-weight: 700;
text-decoration-line: none;
}
tokens.css
:root {
/* Secondary text. 6.8:1 and 6.9:1 on paper. */
--ash: var(--slab-styled-ash, light-dark(#5e5a55, #a8a19a));
--border: 2px solid var(--ink);
/* Behind disabled and read-only controls, and hovered rows. */
--chalk: var(--slab-styled-chalk, light-dark(#f4f1ec, #2b2926));
/*
The logo's orange, brighter in the dark. 4.25:1 and 5.2:1 on paper is
enough for borders, fills and large text, but not always for small text,
which takes "--ember-deep".
*/
--ember: var(--slab-styled-ember, light-dark(#d9492a, #ec5f3b));
/*
Orange for small text on paper, and for paper text on it. 5.7:1 and
7.4:1.
*/
--ember-deep: var(--slab-styled-ember-deep, light-dark(#b3381a, #ff8566));
--font-body: var(
--slab-styled-font-body,
'IBM Plex Sans',
system-ui,
sans-serif
);
--font-display: var(
--slab-styled-font-display,
'Zilla Slab',
rockwell,
'Roboto Slab',
serif
);
--font-mono: var(
--slab-styled-font-mono,
'IBM Plex Mono',
ui-monospace,
monospace
);
--ink: var(--slab-styled-ink, light-dark(#1c1c1c, #f4f1ec));
--paper: var(--slab-styled-paper, light-dark(#fff, #1a1918));
/* The hard, offset shadow a raised surface casts. */
--shadow: 4px 4px 0 var(--ink);
}
/*
Forced colors, such as Windows' contrast themes, replace every color that
isn't a system color, so ember fills and paper marks all become the same
background, and a checked Checkbox looks like an unchecked one. The palette
becomes the user's system colors instead, which are kept. Ember is the
highlight, the color of what's selected, and ember-deep, being for text and
for paper text on it, is the text color.
*/
@media (forced-colors: active) {
:host {
--ash: GrayText;
--chalk: Canvas;
--ember: Highlight;
--ember-deep: CanvasText;
--ink: CanvasText;
--paper: Canvas;
}
}
The same styles, written from outside the element, so
there's nothing to subclass. The CSS styles every
<slab-breadcrumb> on the page. Import
tokens.css, the colors and fonts every styled
example shares, once, wherever your global styles go.
Import breadcrumb.js once, such
as in your root layout, and use
<slab-breadcrumb> as is. A Svelte component
around it would take slot="…" content as its
own slot and drop it.
breadcrumb.js
import 'slab-elements/breadcrumb.js';
import './breadcrumb.css';
breadcrumb.css
slab-breadcrumb::part(list) {
align-items: center;
display: flex;
flex-wrap: wrap;
font-family: var(--font-display);
font-size: 1.0625rem;
gap: 0.5rem;
list-style: none;
margin: 0;
padding: 0;
}
slab-breadcrumb::part(item) {
align-items: center;
display: flex;
gap: 0.5rem;
}
slab-breadcrumb::part(separator)::before {
color: var(--ember);
content: '/';
font-weight: 700;
}
slab-breadcrumb > a {
color: var(--ink);
text-decoration-color: var(--ember);
text-decoration-line: underline;
text-decoration-thickness: 2px;
text-underline-offset: 0.25em;
}
slab-breadcrumb > a:hover {
background-color: var(--ink);
color: var(--paper);
text-decoration-line: none;
}
slab-breadcrumb > a:focus-visible {
outline: 3px solid var(--ember);
outline-offset: 2px;
}
slab-breadcrumb > [aria-current='page'] {
font-weight: 700;
text-decoration-line: none;
}
tokens.css
:root {
/* Secondary text. 6.8:1 and 6.9:1 on paper. */
--ash: var(--slab-styled-ash, light-dark(#5e5a55, #a8a19a));
--border: 2px solid var(--ink);
/* Behind disabled and read-only controls, and hovered rows. */
--chalk: var(--slab-styled-chalk, light-dark(#f4f1ec, #2b2926));
/*
The logo's orange, brighter in the dark. 4.25:1 and 5.2:1 on paper is
enough for borders, fills and large text, but not always for small text,
which takes "--ember-deep".
*/
--ember: var(--slab-styled-ember, light-dark(#d9492a, #ec5f3b));
/*
Orange for small text on paper, and for paper text on it. 5.7:1 and
7.4:1.
*/
--ember-deep: var(--slab-styled-ember-deep, light-dark(#b3381a, #ff8566));
--font-body: var(
--slab-styled-font-body,
'IBM Plex Sans',
system-ui,
sans-serif
);
--font-display: var(
--slab-styled-font-display,
'Zilla Slab',
rockwell,
'Roboto Slab',
serif
);
--font-mono: var(
--slab-styled-font-mono,
'IBM Plex Mono',
ui-monospace,
monospace
);
--ink: var(--slab-styled-ink, light-dark(#1c1c1c, #f4f1ec));
--paper: var(--slab-styled-paper, light-dark(#fff, #1a1918));
/* The hard, offset shadow a raised surface casts. */
--shadow: 4px 4px 0 var(--ink);
}
/*
Forced colors, such as Windows' contrast themes, replace every color that
isn't a system color, so ember fills and paper marks all become the same
background, and a checked Checkbox looks like an unchecked one. The palette
becomes the user's system colors instead, which are kept. Ember is the
highlight, the color of what's selected, and ember-deep, being for text and
for paper text on it, is the text color.
*/
@media (forced-colors: active) {
:host {
--ash: GrayText;
--chalk: Canvas;
--ember: Highlight;
--ember-deep: CanvasText;
--ink: CanvasText;
--paper: Canvas;
}
}
The same styles, written from outside the element, so
there's nothing to subclass. The CSS styles every
<slab-breadcrumb> on the page. Import
tokens.css, the colors and fonts every styled
example shares, once, wherever your global styles go.
Each component registers its headless element and imports its CSS. Use it like the element: its attributes and its content go to the element.
Breadcrumb.gjs
import 'slab-elements/breadcrumb.js';
import './breadcrumb.css';
export const Breadcrumb = <template>
<slab-breadcrumb ...attributes>{{yield}}</slab-breadcrumb>
</template>;
breadcrumb.css
slab-breadcrumb::part(list) {
align-items: center;
display: flex;
flex-wrap: wrap;
font-family: var(--font-display);
font-size: 1.0625rem;
gap: 0.5rem;
list-style: none;
margin: 0;
padding: 0;
}
slab-breadcrumb::part(item) {
align-items: center;
display: flex;
gap: 0.5rem;
}
slab-breadcrumb::part(separator)::before {
color: var(--ember);
content: '/';
font-weight: 700;
}
slab-breadcrumb > a {
color: var(--ink);
text-decoration-color: var(--ember);
text-decoration-line: underline;
text-decoration-thickness: 2px;
text-underline-offset: 0.25em;
}
slab-breadcrumb > a:hover {
background-color: var(--ink);
color: var(--paper);
text-decoration-line: none;
}
slab-breadcrumb > a:focus-visible {
outline: 3px solid var(--ember);
outline-offset: 2px;
}
slab-breadcrumb > [aria-current='page'] {
font-weight: 700;
text-decoration-line: none;
}
tokens.css
:root {
/* Secondary text. 6.8:1 and 6.9:1 on paper. */
--ash: var(--slab-styled-ash, light-dark(#5e5a55, #a8a19a));
--border: 2px solid var(--ink);
/* Behind disabled and read-only controls, and hovered rows. */
--chalk: var(--slab-styled-chalk, light-dark(#f4f1ec, #2b2926));
/*
The logo's orange, brighter in the dark. 4.25:1 and 5.2:1 on paper is
enough for borders, fills and large text, but not always for small text,
which takes "--ember-deep".
*/
--ember: var(--slab-styled-ember, light-dark(#d9492a, #ec5f3b));
/*
Orange for small text on paper, and for paper text on it. 5.7:1 and
7.4:1.
*/
--ember-deep: var(--slab-styled-ember-deep, light-dark(#b3381a, #ff8566));
--font-body: var(
--slab-styled-font-body,
'IBM Plex Sans',
system-ui,
sans-serif
);
--font-display: var(
--slab-styled-font-display,
'Zilla Slab',
rockwell,
'Roboto Slab',
serif
);
--font-mono: var(
--slab-styled-font-mono,
'IBM Plex Mono',
ui-monospace,
monospace
);
--ink: var(--slab-styled-ink, light-dark(#1c1c1c, #f4f1ec));
--paper: var(--slab-styled-paper, light-dark(#fff, #1a1918));
/* The hard, offset shadow a raised surface casts. */
--shadow: 4px 4px 0 var(--ink);
}
/*
Forced colors, such as Windows' contrast themes, replace every color that
isn't a system color, so ember fills and paper marks all become the same
background, and a checked Checkbox looks like an unchecked one. The palette
becomes the user's system colors instead, which are kept. Ember is the
highlight, the color of what's selected, and ember-deep, being for text and
for paper text on it, is the text color.
*/
@media (forced-colors: active) {
:host {
--ash: GrayText;
--chalk: Canvas;
--ember: Highlight;
--ember-deep: CanvasText;
--ink: CanvasText;
--paper: Canvas;
}
}