Skip to main content
Login

Sign in to access your account

TOC - National Design System

A table of contents for a long page, built from its headings, that marks the section the reader is on

Overview

A TOC lists the sections of a long page and links to each one. It has a head with a label and the page title, and a lined Drawer that holds the links. The script builds the links from the page’s headings, or reads a list you write.

Pick another component when:

  • the links go to other pages, not to sections of this page: Drawer
  • the page is a form or a flow in steps: Stepper
  • the reader switches between panels in one place: Tabs

Markup

Auto-built List

The TOC sits in a sticky Side Info column next to the article it lists. Preview opens it in a panel, where the article can scroll.

Preview
<section id="policy-page" class="nds-content-section nds-sideinfo-section"> <div class="nds-section-body"> <aside class="nds-sideinfo nds-sticky nds-top" aria-label="On this page" data-i18n-aria-label="toc.on_this_page"> <nav class="nds-toc" aria-label="Table of contents" data-i18n-aria-label="toc.table_of_contents" style="--toc-skeleton-rows: 5" data-toc-source="#policy-page article" data-toc-levels="h2,h3"> <div class="nds-toc-head"> <span class="nds-label" data-i18n="toc.on_this_page">On this page</span> <h2 class="nds-toc-title nds-truncate">Privacy Policy</h2> </div> <div class="nds-drawer nds-lined"> <ul class="nds-drawer-list"></ul> </div> </nav> </aside> <div class="nds-info-content"> <article class="nds-prose"> <h2 id="data-we-collect">Data we collect</h2> <p>The portal stores your name, national ID and contact details when you create an account.</p> <p>It also records the date and time of each sign-in, to protect your account.</p> <h3 id="data-from-requests">Data from requests</h3> <p>Each service request keeps the documents you upload and the status of the request.</p> <p>Documents stay in your account for five years after the request closes.</p> <h2 id="how-we-use-data">How we use your data</h2> <p>The portal uses your data to process requests and to send you updates about them.</p> <p>It never uses your data for advertising, and never sells it.</p> <h2 id="data-sharing">Data sharing</h2> <p>Your data is shared only with the government agency that handles your request.</p> <p>An agency sees only the data that its service needs.</p> <h3 id="your-rights">Your rights</h3> <p>You can ask for a copy of your data, or ask the portal to correct it.</p> <p>The portal answers each request within 30 days.</p> </article> </div> </div> </section>

Manual List

You write the links. Nest a <ul> inside an <li> for each level.

<nav class="nds-toc" aria-label="Table of contents" data-i18n-aria-label="toc.table_of_contents"> <div class="nds-toc-head"> <span class="nds-label" data-i18n="toc.on_this_page">On this page</span> <h2 class="nds-toc-title nds-truncate">Annual Report 2025</h2> </div> <div class="nds-drawer nds-lined"> <ul class="nds-drawer-list"> <li> <a href="#summary" class="nds-btn nds-subtle nds-indicator"> <span class="nds-label nds-truncate">Summary</span> </a> </li> <li> <a href="#services" class="nds-btn nds-subtle nds-indicator"> <span class="nds-label nds-truncate">Services</span> </a> <ul> <li> <a href="#licenses" class="nds-btn nds-subtle nds-indicator"> <span class="nds-label nds-truncate">Licenses</span> </a> <ul> <li> <a href="#new-licenses" class="nds-btn nds-subtle nds-indicator"> <span class="nds-label nds-truncate">New licenses</span> </a> </li> <li> <a href="#renewals" class="nds-btn nds-subtle nds-indicator"> <span class="nds-label nds-truncate">Renewals</span> </a> </li> </ul> </li> <li> <a href="#appointments" class="nds-btn nds-subtle nds-indicator"> <span class="nds-label nds-truncate">Appointments</span> </a> </li> </ul> </li> <li> <a href="#contact" class="nds-btn nds-subtle nds-indicator"> <span class="nds-label nds-truncate">Contact us</span> </a> </li> </ul> </div> </nav>

Behavior

Auto-built List

data-toc-source on .nds-toc names the container to read, as a CSS selector. At init, the script replaces the list with a link to each heading in it, nested by level. data-toc-levels picks the levels, such as h2 for a flat list. The script builds the list once. After the headings change, call NDS.Toc.destroy(toc), then NDS.Toc.create(toc). A heading with no id gets one made from its text, Arabic included, so its link works. Until the list fills in, it keeps the height of --toc-skeleton-rows links, so the content under it does not move. A TOC that finds no headings at load stays empty, and NDS.init.refresh() builds it once the headings are in the page.

Manual List

Without data-toc-source, the script reads the links you write. Pick it for some sections only, for anchors that are not headings, or for a shorter label when a heading is too long for the column. Each link’s href must match an id on the page, or the link is left out of the tracking.

Built-in Features

  • Auto-initialization

    Every .nds-toc on the page starts by itself, before the page shows.

  • Heading Ids

    A heading with no id gets one from its text. Two headings with the same text get two ids, such as setup and setup-2, so each link goes to its own heading.

  • Active-Section Tracking

    As the reader scrolls, the link to the last section that passed under the main navigation shows as active. No link is active until the first section reaches the top. When the article scrolls in a panel or a modal, the TOC tracks and scrolls that box instead of the page.

  • Click-to-Scroll

    A click scrolls the heading to just below the main navigation and updates the URL hash, with no new history entry. The scroll is instant when the reader asks for reduced motion.

  • Nested Levels

    Each nested list is indented, with a line along it, so the reader sees each section's level at a glance.

  • JavaScript API

    Start or stop a TOC from code, and check the active link again after the layout changes.

Best Practices

  • Use a TOC on long pages: policies, guides and reports. On a short page that fits on the screen, leave it out.
  • Use the auto-built list when the links match the headings. It lists every heading at load, so a new section needs no TOC edit.
  • Give every heading its own short id. An id made from the text changes when the text changes, and breaks the links people shared.
  • Keep the list to three levels or fewer. A deeper list is hard to scan, and often means the page should be split. Set data-toc-levels="h2,h3" when the page uses h4 for small labels, not sections.
  • Set --toc-skeleton-rows on .nds-toc to the number of links the page has. On a phone, the TOC sits above the article, so a wrong count moves the article when the list fills in.
  • Put the TOC in a sticky .nds-sideinfo, so it stays in view. The column is 300px wide for a TOC: --nds-sideinfo-width changes it.
  • Give the <nav> an aria-label, so screen reader users can tell it from the page’s other navigation.
  • Let the script mark the active link. It sets data-state="active" from the scroll position, and clears any the markup carries at init.

API

Classes

Class Element Effect
nds-toc <nav> The TOC. Holds the head and the drawer
nds-toc-head <div> The head: a label and the title. Optional
nds-toc-title the heading in the head The page title, in larger semibold type
nds-lined .nds-drawer Required. The line along each nested list
nds-loading .nds-toc The link labels show as pulsing bars. Use it while the page loads the content

Data Attributes

Attribute Element Effect
data-toc-source .nds-toc A CSS selector for the container whose headings build the list. It replaces the list you write
data-toc-levels .nds-toc The heading levels to list, comma-separated. Default h2,h3,h4
data-state="loading" .nds-toc The same as nds-loading, for a script that already sets states
data-state="active" <li> and its link Set by the script on the link to the current section. It also writes aria-current="true" on that link, and removes it when the section changes

CSS Custom Properties

Property Default Controls
--toc-skeleton-rows 6 Links an auto-built list reserves height for before it fills in, at 36px each. Set it on .nds-toc
--drawer-lined-width 2px Width of the line along nested lists. The TOC sets it on .nds-toc
--drawer-lined-block 0px Space cut from the top and the bottom of that line. The TOC sets it on .nds-toc
--drawer-indicator-width 3px Width of the active link’s line. The TOC sets it on its .nds-drawer, so set a new value there

Tokens

It reads these shared tokens. A change to one also changes other components: see Tokens.

Source: the var() reads in _sass/components/_toc.scss.

TokenPreviewValue
--text-display
Read by color, --btn-color

var(--colors-neutral-800)
Dark mode var(--colors-neutral-100)
--text-primary-paragraph
Read by color

var(--colors-neutral-700)
Dark mode var(--colors-neutral-300)
--button-indicator-mark
Read by --btn-indicator-color, --btn-indicator-selected

var(--background-primary)
Dark mode var(--colors-primary-500)

JavaScript

Method Effect
NDS.Toc.init() Starts every TOC on the page that has not started yet
NDS.Toc.create(toc) Starts one TOC and returns its instance. Returns the running one when toc already has one, and null when no link points at an element on the page
NDS.Toc.destroy(toc) Removes the listeners and the active mark of the link. NDS.init.destroy() calls it for every TOC in the container it releases
instance.refresh() Picks the active link again from the scroll position. Call it after the layout above the headings changes

The TOC fires no events.

var toc = document.querySelector('.nds-toc'); // The article's headings changed: build the list again. NDS.Toc.destroy(toc); NDS.Toc.create(toc);

The full API is in the banner of _js/nds-toc.js.

Last Modified Date: 05/11/2026 - 12:02 PM
Was this page useful?
60% of users said Yes from 2843 Feedbacks