Subnav
A vertical navigation for a sidebar, whose sections open in place: a parent page is its link with a toggle beside it, and its pages open below both.
Example
View Code
<nav class="subnav" aria-label="Docs">
<ul role="list">
<li><a href="#">Overview</a></li>
<li>
<a href="#">Layouts</a>
<details open>
<summary aria-label="Layouts pages"></summary>
<ul role="list">
<li><a href="#" aria-current="page">Stack</a></li>
<li><a href="#">Grid</a></li>
<li><a href="#">Sidebar</a></li>
</ul>
</details>
</li>
<li>
<a href="#">Components</a>
<details>
<summary aria-label="Components pages"></summary>
<ul role="list">
<li><a href="#">Button</a></li>
<li><a href="#">Card</a></li>
</ul>
</details>
</li>
<li>
<details>
<summary>Reference</summary>
<ul role="list">
<li><a href="#">Tokens</a></li>
<li><a href="#">Vocabulary</a></li>
</ul>
</details>
</li>
</ul>
</nav>
When to use it
A sidebar: the pages of a docs site, a section of a large site, a settings area. Use subnav for any navigation that stays a column and never becomes a desktop top bar. Its sections open in place and push the rest of the list down, which suits a column and would break a bar.
For a site's main navigation, the row across the top that folds into a panel on a phone, use a nav with dropdowns instead. A dropdown opens as a panel over the page, which suits a bar.
How it works
A list of links. A parent page is its link followed by a details that holds its pages. The link goes to the parent's own page, and the summary is only the toggle, a control-sized square at the end of the link's row showing the chevron. The parent's pages open below both, one indent further in. The browser does the opening, the keyboard and the announcing, so the component needs no ids and no script.
<nav class="subnav" aria-label="Docs">
<ul role="list">
<li><a href="/docs/">Overview</a></li>
<li>
<a href="/docs/layouts/">Layouts</a>
<details open>
<summary aria-label="Layouts pages"></summary>
<ul role="list">
<li><a href="/docs/layouts/stack/" aria-current="page">Stack</a></li>
<li><a href="/docs/layouts/grid/">Grid</a></li>
</ul>
</details>
</li>
<li>
<details>
<summary>Reference</summary>
<ul role="list">
<li><a href="/docs/tokens/">Tokens</a></li>
</ul>
</details>
</li>
</ul>
</nav>
A parent that is not a page has no link. It is a plain details with the section's name in its summary, so the whole row is the toggle, as any disclosure on the page is.
The same shape nests. A list inside a details can hold another parent with its own details, and each level steps in by --yeti-subnav-indent. A title that wraps onto a second line keeps its toggle beside the first line.
The page the reader is on carries aria-current="page" and takes the current color in the strong weight. Each parent that holds it shows its own row in the same color, so the reader can see which section they are in. A parent with its own link shows that link at the normal weight. A parent that is not a page keeps the strong weight every summary has and only changes color. The color is --yeti-subnav-current, read with a fallback to the variant's text color, and data-variant picks the hue. To fill the current page's row as well, set --yeti-subnav-current-surface. It is off until you set it, and only the page's own link takes it, not the parents above.
Open the way to the current page in the template: write open on each details above it. CSS cannot open a details, and the component adds no script to do it, so a page that leaves open off arrives with its own section shut.
A section grows open rather than appearing, with the same transition as every other details in Yeti. Under prefers-reduced-motion it simply appears.
To keep one section open at a time, give sibling details the same name. That is the browser's own exclusive disclosure, and it needs nothing from Yeti.
A link or a toggle under the pointer takes --yeti-subnav-hover, read with a fallback to the variant's subtle tint, so setting it to transparent turns the fill off without touching the variant.
View Code
<nav class="subnav" aria-label="Settings" data-variant="secondary">
<ul role="list">
<li>
<details name="settings" open>
<summary>Account</summary>
<ul role="list">
<li><a href="#" aria-current="page">Profile</a></li>
<li><a href="#">Password</a></li>
</ul>
</details>
</li>
<li>
<details name="settings">
<summary>Billing</summary>
<ul role="list">
<li><a href="#">Plan</a></li>
</ul>
</details>
</li>
</ul>
</nav>
Accessibility
Label the nav, with aria-label="Docs" or similar, because a page with a sidebar has at least two navs and they have to be told apart. Put role="list" on every ul, which keeps each one a list where the reset removes the markers.
A toggle beside a link has no text, so give its summary an aria-label that names the section's pages, such as "Layouts pages". The summary is the browser's own disclosure button: Tab reaches it, Enter or Space opens and closes its section, and its open state is announced. The pages of a closed section are skipped by Tab.
Never put the link inside the summary. A summary is a button, and a link inside a button is lost to screen readers.
The current page's aria-current="page" is what a screen reader announces; the color and the weight are the visible half of the same fact. Focus rings are drawn inside each row, so an opening section or a scrolling sidebar never cuts their edges.
Attributes
| Attribute | Type | Values | Default | Description |
|---|---|---|---|---|
data-variant |
enum | primary, secondary, success, warning, alert, danger, neutral, black, white |
primary |
The hue of the current page, its parents' rows, and the hover fill. |
Children
> ul: exactly 1. The links, one per li, with role="list".li: at least 1. One entry: a link, a link followed by a details holding its pages, or a details alone for a parent that is not a page. Each li holds at most one link and at most one details, as its own children.a: at least 1. A page. The current one carries aria-current="page".details: any number. A parent's pages, after its link or alone in its li. The template writes open on each details above the current page.summary: any number. The toggle, first in each details. Beside a link it is empty and named by aria-label; without a link it holds the section's name. After it, each details holds one ul with role="list", one indent further in, which may nest the same shape again.
Tokens
| Token | Description |
|---|---|
--yeti-subnav-indent |
How far each level steps in. |
--yeti-subnav-hover |
The fill under the pointer; transparent turns it off. |
--yeti-subnav-current-surface |
Background of the current page's link; off unless set. The parents above it are not filled. |
--yeti-subnav-current |
The current page, and the rows of the parents that hold it. |
--yeti-control-size |
A row's least height, and the toggle's square. |
--yeti-space-xs |
A row's block padding. |
--yeti-space-sm |
A row's inline padding. |
--yeti-color-text |
A link that is not current. |
--yeti-weight-strong |
Weight of the current page's link. |
--yeti-duration-base |
How long a section takes to open or close. |
--yeti-ease |
The curve of that transition. |
--yeti-color-primary-subtle |
The default variant's hover fill. |
--yeti-color-primary-text |
The default variant's current color. |
Internal tokens (may change between minor versions)
- `--_yeti-variant-subtle` - `--_yeti-variant-text`Accessibility
- Required attributes:
aria-labeloraria-labelledby - Give the nav an aria-label such as "Docs", since a page with a sidebar has at least two navs. Put role="list" on every ul, because the reset only removes list markers where that role says the list is decorative. The current page's link carries aria-current="page". A toggle beside a link has no text, so its summary carries an aria-label naming the section's pages, such as "Layouts pages". The summary is the browser's own disclosure button: it takes the keyboard and announces whether its section is open. Never put the link inside the summary, because a link inside a button is lost to screen readers.
| Key | Action |
|---|---|
Tab |
Moves through the links and toggles in order; the pages of a closed section are skipped. |
Enter / Space |
Opens or closes the section under the focused toggle. |
Browser support
- Used without guards: :has(), subgrid, ::details-content, details name attribute, animating a grid row between 0fr and 1fr
- Behind
@supports: nothing
JavaScript
None. This component is CSS only.
Available since 7.0.0.