Tabnav
A row of links to sibling pages, styled as tabs with the current page marked, that scrolls sideways when it is too narrow.
Example
View Code
<nav class="tabnav" aria-label="Repository">
<ul role="list">
<li><a href="#" aria-current="page">Code</a></li>
<li><a href="#">Issues</a></li>
<li><a href="#">Pull requests</a></li>
<li><a href="#">Discussions</a></li>
<li><a href="#">Actions</a></li>
<li><a href="#">Projects</a></li>
<li><a href="#">Wiki</a></li>
<li><a href="#">Security</a></li>
<li><a href="#">Insights</a></li>
<li><a href="#">Settings</a></li>
</ul>
</nav>
When to use it
A row of links to sibling pages, with the current one marked. Think of a repository's Code, Issues and Pull requests, or the sections of an account area. Each tab is its own page, so the row is navigation and every tab has a URL.
Use tabs instead when the panels are all on one page and a tab only switches which one shows. That component has the tab roles, the arrow keys and a script. tabnav has none of them: it is a list of links that looks like tabs. For a column of links in a sidebar, use subnav.
How it works
A nav holding one list, one link per item. The current page's link carries aria-current="page". A tab for a section that holds the current page may carry aria-current="true". Any value but false marks the link.
<nav class="tabnav" aria-label="Repository">
<ul role="list">
<li><a href="/code/" aria-current="page">Code</a></li>
<li><a href="/issues/">Issues</a></li>
<li><a href="/pulls/">Pull requests</a></li>
</ul>
</nav>
The links sit in one row and their text never wraps. A rule in --yeti-tabs-border runs along the bottom. The marked link takes the variant's text color, and its edge in the variant's color covers the rule. A link under the pointer takes the variant's subtle tint. The look is the same as tabs: the same spacing between tabs, the same transition, and the same two tokens, --yeti-tabs-border and --yeti-tabs-padding, so a theme that restyles one restyles both. A tab that is taller than the rest, with an icon or a badge, does not lift the others off the rule: every link fills its item's height.
data-variant picks the hue, primary by default. data-emphasis="high" fills the marked link with the variant, as a solid chip with rounded top corners.
View Code
<nav class="tabnav" aria-label="Account" data-variant="secondary" data-emphasis="high">
<ul role="list">
<li><a href="#" aria-current="page">Profile</a></li>
<li><a href="#">Keys</a></li>
<li><a href="#">Billing</a></li>
</ul>
</nav>
When the links do not fit, the row scrolls sideways inside itself. The page does not, even when the tabnav sits in a flex or grid row. The rule stays put while the links move.
The reader needs a sign that there is more. The browser's own scrollbar is always there. Where it is a classic one it is thin, and it sits inside the row, between the links and the rule. Where it is an overlay one, as on a phone, it shows nothing at rest. Where the browser supports scroll timelines, the row also fades out at whichever edge has more links beyond it. At the start only the end fades, at the end only the start fades, and a row that fits does not fade at all. Each fade grows over the first tenth of the scroll and shrinks over the last tenth, so on a row that overflows by only a few pixels it appears at once. The fade follows the reader's own scrolling and does not move on its own, so it stays under prefers-reduced-motion.
Where the browser supports scroll-initial-target, the row opens scrolled so the marked link is in view, stopped just clear of the faded edge. That matters on a phone, where the current tab is often past the edge. A browser without it starts the row at its start.
There is no script. Nothing to load, and no ids to wire up.
Accessibility
Label the nav, with aria-label="Repository" or similar, because the page has at least one other nav and they have to be told apart. Put role="list" on the ul, which keeps WebKit announcing it as a list once its markers are gone.
These are links, not tabs. Do not add role="tablist" or role="tab": a screen reader would then promise arrow keys and panels that are not there. Tab moves through the links in order, and Enter follows one. The row scrolls to bring each focused link into view.
The current page's aria-current="page" is what a screen reader announces; the color and the edge are the visible half of the same fact. The row clips what overflows it, so focus rings are drawn inside each link and are never cut off.
Attributes
| Attribute | Type | Values | Default | Description |
|---|---|---|---|---|
data-variant |
enum | primary, secondary, success, warning, alert, danger, neutral, black, white |
primary |
The hue of the current link, its edge, and the hover fill. |
data-emphasis |
enum | high |
The current link is filled with the variant; without it the current link is underlined. |
Children
> ul: exactly 1. The links, one per li, with role="list", which keeps WebKit announcing it as a list once the markers are gone.li: at least 1. One tab, holding one link.a: at least 1. A page. The current one carries aria-current="page"; a tab for a section that holds the current page may carry aria-current="true".
Tokens
| Token | Description |
|---|---|
--yeti-tabs-border |
The rule along the bottom of the row. |
--yeti-tabs-padding |
Padding of one link. |
--yeti-border-width |
Width of the rule; the current link's edge is twice it. |
--yeti-weight-strong |
Weight of a link's label. |
--yeti-radius-sm |
Corner radius of the current link with data-emphasis="high". |
--yeti-space-xs |
Gap between links. |
--yeti-duration-fast |
How long a link takes to change color. |
--yeti-ease |
The curve of that transition. |
--yeti-space-xl |
How wide the fade is at an edge with more links beyond it, and the scroll padding that keeps the marked link clear of it. |
--yeti-color-primary |
The default variant's color, when data-variant is absent. |
--yeti-color-primary-subtle |
The default variant's tint. |
--yeti-color-primary-soft |
The default variant's soft stop. |
--yeti-color-primary-strong |
The default variant's strong stop. |
--yeti-color-primary-text |
The default variant's text color. |
--yeti-color-primary-line |
The default variant's line color for edges and underlines. It has a value only when the primary has a brand color; without one the rule reading it falls back to the variant's color. |
--yeti-on-primary |
Text on the default variant's color. |
Internal tokens (may change between minor versions)
- `--_yeti-variant` - `--_yeti-variant-subtle` - `--_yeti-variant-soft` - `--_yeti-variant-strong` - `--_yeti-variant-text` - `--_yeti-variant-line` - `--_yeti-on-variant` - `--_yeti-tabnav-fade-start` - `--_yeti-tabnav-fade-end`Accessibility
- Required attributes:
aria-labeloraria-labelledby - Give the nav an aria-label such as "Repository", since the page has at least one other nav. Put role="list" on the ul, which keeps WebKit announcing it as a list once its markers are gone. The current page's link carries aria-current="page"; a tab for a section that holds the current page may carry aria-current="true". These are links, not tabs: there is no tablist role, no arrow keys and no script. For panels that switch on one page, use tabs.
| Key | Action |
|---|---|
Tab |
Moves through the links in order, scrolling the row to bring each one into view. |
Enter |
Follows the focused link. |
Browser support
- Used without guards: logical properties, :dir(), overscroll-behavior-inline, scrollbar-width, scroll-initial-target (where missing, the row starts at its start)
- Behind
@supports: animation-timeline: scroll() (fallback: no fade; the browser's own scrollbar, which is always there, is the only signal)
JavaScript
None. This component is CSS only.
Available since 7.0.0.