Build Components

Anchor navigation

An on-this-page list that marks the section being read with aria-current, and moves focus when you follow it.

Pattern
Table of contents + aria-current
Category
Navigation · Within a page
Outputs
React + Tailwind (Next.js or any React app), HTML/CSS/JS, Vue (Nuxt), Svelte (SvelteKit), Astro, Angular, Solid, Web Component
Status
In stock, tested

Test bench

Runs the exported code, not a mock-up.

Output
Screen width

Anchor navigation · React + TailwindFull width

Keyboard map
KeysWhat happens
TabDown the list of sections. It is a list of links, so every one is a stop.
EnterJump to that section. Focus lands on its heading, so the next Tab carries on from there.

Take it home

React + Tailwind CSS v4: install with one command, or copy the file. Your options are already in it.

npx shadcn@latest add "/r/anchor-nav.json"

Run it in your project root. It writes components/anchor-nav.tsx with the options you set here. Needs Tailwind CSS v4 and a project set up for the shadcn CLI (npx shadcn@latest init).

Use it with your own data

import { AnchorNav } from "@/components/anchor-nav";

<AnchorNav config={{ sections: yourData }} />

Pass only what changes: the rest keep the options set in the file. sections takes the same shape as the file's own list.

Changes

This is 1.3.0. A copy you took names its version on its first line.

  1. 1.3.013 October 2026

    Added. The React component takes config as just the options you pass, so data from your page (a list of products, the options of a select) goes straight in; the rest keep the file's defaults. Every file now carries its licence: MIT.

  2. 1.2.09 October 2026

    Added. An Astro file, and the Vue and Svelte files now tested in Nuxt and SvelteKit too: rendered on the server, then started in the browser.

  3. 1.1.04 October 2026

    Added. Takes the site theme when a page has one: colours, corners, body font, and the page's own light or dark choice.

  4. 1.0.03 October 2026

    Released. As it was on the site when versions began.

Follow changes to Anchor navigation (RSS)

Last test run

5 October 2026, at commit 0adb641: this part's own tests, in every output: React, HTML/CSS/JS and the five framework files.

  • Chromium50 passed
  • WebKit (Safari's engine)50 passed
  • iPhone, emulated50 passed

What every part is tested for

Found a problem?

Write to us: the subject already names the part and this version.

Report a problem with Anchor navigation