The selected item of a row or a column of tabs, marked by an indicator that moves like a shape.
ax-navigation marks the selected one of its ax-navigation-item children with an indicator. When you pick another item the indicator stretches toward it and then shrinks onto it, and the two ends move as damped springs, so one can lead while the other follows.
The indicator is a shape of @ax-design/surface, drawn on a canvas. It reads the shape contract (--ax-radius, --ax-corner-* and --ax-edge-{top,right,bottom,left}-*), so any shape of the Shape page (/components/shape) works as an indicator, and a feature can be driven by the movement itself with calc() and the spring values the element writes.
The shape is drawn into a frame that does not depend on the direction: --navigation-indicator-width goes across the bar and the item supplies the length along it. In a vertical navigation top and bottom are still the long sides, top facing the content, and right and left are still the end the indicator moves toward and the end it starts from.
Installation
npm install @ax-design/navigationand import it:
import { register } from '@ax-design/navigation';
register();If you don't use a bundler, load the script instead:
<script src="https://unpkg.com/@ax-design/navigation/build/main.js"></script>
<script>AxNavigation.register();</script>Horizontal
The default is a row of items with the indicator below the selected one. Click an item to move the indicator. --navigation-indicator-color paints it, and --navigation-indicator-width is its thickness.
Without either the vertical or the horizontal attribute the element adds horizontal itself, so a plain ax-navigation is a row.
Try it
<ax-navigation>
<ax-navigation-item>Home</ax-navigation-item>
<ax-navigation-item>Apps</ax-navigation-item>
<ax-navigation-item>Games</ax-navigation-item>
</ax-navigation>ax-navigation {
--navigation-indicator-color: rgb(255, 255, 255);
--navigation-indicator-width: 2px;
}Vertical
Add the vertical attribute and the items stack in a column, with the indicator beside them. --navigation-indicator-speed is the time the indicator takes to travel from one item to another.
The frame turns with the direction, but the shape does not: top and bottom stay the long sides, and top stays the side facing the content.
Try it
<ax-navigation vertical>
<ax-navigation-item>Home</ax-navigation-item>
<ax-navigation-item>Apps</ax-navigation-item>
<ax-navigation-item>Games</ax-navigation-item>
</ax-navigation>ax-navigation {
--navigation-indicator-speed: 600ms;
}Shape
The indicator is a Surface shape, so it takes the same custom properties that a surface takes. Give it a width worth shaping and it can be a pill, a parallelogram or anything else: shift the top left and the bottom right corner on x and the bar slants.
Only the border and the tilt properties of Surface are not read. The frame is --navigation-indicator-width across the bar and the item long, so corners and side features follow the size of the item. The shape is drawn on one canvas at rest and while it moves, so the two always agree.
The layout keeps free the space an outward feature takes on the side away from the content; on the side facing the content the feature draws over the items.
Try it
<ax-navigation>
<ax-navigation-item>Home</ax-navigation-item>
<ax-navigation-item>Apps</ax-navigation-item>
<ax-navigation-item>Games</ax-navigation-item>
</ax-navigation>ax-navigation {
--navigation-indicator-width: 12px;
--ax-radius: 0px;
--ax-corner-shape: bevel;
--ax-corner-top-left-shift-x: 8px;
--ax-corner-bottom-right-shift-x: 8px; /* a parallelogram */
}Moving
While the indicator travels, the element carries the moving attribute, forward or backward: forward is toward the end of the item order, right in a row and down in a column. The attribute goes away when the indicator arrives, and an interrupted movement starts over.
The element also writes what each part of the movement is doing. --navigation-indicator-arrival and --navigation-indicator-follow are the times the leading end and the trailing end take. --navigation-indicator-lead and --navigation-indicator-trail are how deformed each end is, as numbers, driven by a spring of its own. The general --navigation-indicator-deform-stiffness and --navigation-indicator-deform-damping set both springs; the lead and trail properties override them for one end.
A feature is shaped from a deformation with calc(), and the shape is read on every frame, which also keeps it working where CSS.registerProperty is missing. Click back and forth: the leading end grows a triangle, the trailing end pulls one in, and the rule for moving="backward" swaps which side is which.
Try it
ax-navigation {
--navigation-indicator-width: 12px;
--navigation-indicator-speed: 600ms;
--navigation-indicator-deform-stiffness: 400;
--navigation-indicator-deform-damping: 32;
--ax-edge-right-kind: triangle;
--ax-edge-right-span: 100%;
--ax-edge-left-kind: triangle;
--ax-edge-left-span: 100%;
--ax-edge-right-depth: calc(var(--navigation-indicator-lead, 0) * 9px);
--ax-edge-left-depth: calc(var(--navigation-indicator-trail, 0) * -7px);
}
/* Backward, the leading end is the left one. */
ax-navigation[moving="backward"] {
--ax-edge-right-depth: calc(var(--navigation-indicator-trail, 0) * -7px);
--ax-edge-left-depth: calc(var(--navigation-indicator-lead, 0) * 9px);
}navigation.addEventListener('switch', (event) => {
// forward or backward: the way the indicator just went.
navigation.getAttribute('moving');
});Default item
The first item is selected at the start. Add the default attribute to another item to select that one instead.
Try it
<ax-navigation>
<ax-navigation-item>Home</ax-navigation-item>
<ax-navigation-item default>Apps</ax-navigation-item>
<ax-navigation-item>Games</ax-navigation-item>
</ax-navigation>ax-navigation {
--navigation-indicator-color: rgb(255, 255, 255);
}click an item
Switch event
The ax-navigation element fires a switch event when the indicator goes from one item to another. The detail holds the item before (from) and the item after (to). The event does not bubble and is not cancelable.
Click an item in the preview; the text below shows the last event.
Try it
const navigation = document.querySelector('ax-navigation');
navigation.addEventListener('switch', (event) => {
console.log(event.detail.from.textContent, event.detail.to.textContent);
});

Accessibility
Keyboard: Tab enters the navigation on the current item. The Left and Right arrows move between the items (Up and Down in a vertical one), Home and End go to the first and last, and Enter or Space select the focused item. Moving focus does not select.
Screen readers: Items get the roles of a tab list: the element is a tablist, and the items are tabs with aria-selected. Give the element a name with aria-label. A row of links is a navigation, and its current link gets aria-current. The panels are yours: point each tab at its panel with aria-controls.
High contrast (forced colors): The indicator is painted with Highlight, the system color, instead of its indicator color.
Reduced motion: The indicator moves at once, without its springs.
Try it: in Chrome or Edge, open DevTools, then Rendering, and emulate the CSS media features prefers-reduced-motion, forced-colors or prefers-reduced-transparency. Or turn on the setting of your system: Show animations, Contrast themes and Transparency effects on Windows; Reduce motion, Increase contrast and Reduce transparency on macOS.
Try it
<ax-navigation aria-label="Settings">
<ax-navigation-item aria-controls="panel-general">General</ax-navigation-item>
<ax-navigation-item aria-controls="panel-privacy">Privacy</ax-navigation-item>
</ax-navigation>Reference
horizontal, vertical attribute
boolean
On ax-navigation: the direction of the items and of the indicator. Without either the element adds horizontal.
default attribute
boolean
On ax-navigation-item: the item that is selected at the start. Without it, the first item.
moving attribute
forward | backward
Written by the element while the indicator travels: forward is toward the end of the item order (right in a row, down in a column), backward the other way. Removed when the indicator arrives. Read it to style the two directions apart.
block, inline-block, flex, inline-flex, grid, inline-grid attribute
boolean
On ax-navigation or ax-navigation-item: how the element is displayed. A shortcut for a display rule, which an author rule cannot reach into the shadow root.
--navigation-indicator-speed property
<time>, default 600ms
How long the indicator takes to travel from one item to another. The two ends keep their own springs on top of it.
--navigation-indicator-color property
<color>, default rgb(0, 0, 0)
The color of the indicator shape.
--navigation-indicator-width property
<length>, default 2px
The thickness of the indicator, across the bar. The length along the bar is the item.
--ax-radius, --ax-corner-*, --ax-edge-* property
as on the Shape page
The shape of the indicator, with the names of the Shape page (/components/shape). The general edge properties set every side at once. The border and tilt properties of Surface are not read.
--navigation-indicator-arrival, --navigation-indicator-follow property
<time>, default 0ms
Written by the element: the time the leading end takes to reach the item, and the time the trailing end takes to follow it. Give an animation the length of the part whose end carries it.
--navigation-indicator-lead, --navigation-indicator-trail property
<number>, default 0
Written by the element: how deformed the leading end and the trailing end are. Shape a feature from them with calc(); the numbers are read on every frame.
--navigation-indicator-deform-stiffness, --navigation-indicator-deform-damping property
<number>, default 400, 32
How hard both springs follow. A larger stiffness makes an end answer sooner; a larger damping makes it settle without overshooting.
--navigation-indicator-{lead,trail}-stiffness, --navigation-indicator-{lead,trail}-damping property
<number>, default -1 (use the general value)
The spring of one end, overriding the general pair. The trailing end is only asked to follow while the leading end is more than half deformed, so the two overlap.
switch event
CustomEvent<{ from, to }>
Fired on ax-navigation when the indicator goes to another item. Does not bubble, is not cancelable. from and to are the items.
currentItem property
AxNavigationItem | undefined
The item the indicator marks. It starts as the item with default, or the first one, and follows the clicks.
register() method
() => void
Defines ax-navigation and ax-navigation-item and registers the shape and spring properties. Safe to call more than once.
AxNavigation, AxNavigationItem property
class
The two element classes. AxNavigation holds the canvas and the indicator manager; AxNavigationItem knows its container and reports clicks to it.
NAVIGATION_PROPERTIES, SPEED_PROPERTY, WINDOW_PROPERTIES property
PropertySpec[]
The property contract, for a tool: the properties the element reads, the speed property registered as a <time>, and the arrival, follow, lead and trail properties it writes.