Skip to content

Table of Contents

Use the af-toc pattern to style in-page navigation (e.g. “On this page” lists, long-form docs, multi-section pages).

Use semantic HTML:

  • nav with aria-label
  • an optional heading (h2/h3) for the TOC title
  • ol/ul for the list

If you can set aria-current="page" on the active anchor, the TOC will highlight it.

The pattern also styles semantic TOCs without the class when the nav’s label suggests “contents”:

  • If you’re using the docs site, Starlight’s built-in TOC uses nav[aria-label="Table of contents"], which this pattern can style without extra markup changes.
  • You can nest lists (ol > li > ol) for hierarchical pages.