On-Page TOC
The canonical wiring for an in-page TOC alongside long-form content — articles, docs pages, change logs, anything with five or more headings. WireKit ships two primitives that map onto the two common shapes:
- Sidebar TOC (
<x-wirekit::) — right-edge sticky vertical sidebar, hover-to-expand, narrow at rest, the shape many documentation sites use. Recommended for docs / articles.reading-spine> - Horizontal strip TOC (
<x-wirekit::) — sticky strip across the top of the viewport. Right shape for flat marketing pages with 3-4 anchored sections. See the marketing-landing-toc recipe.reading-toc>
This recipe covers the sidebar pattern.
The canonical wiring
Three primitives compose:
<x-wirekit::— the top-edge progress bar (full-page, not scoped to article). Optional; drop if your layout doesn't want one.reading-progress> <x-wirekit::— the right-edge sidebar TOC. Readsreading-spine> <main>headings at the H2 / H3 levels.expand="hover"keeps the spine narrow at rest; expands to show labels on hover.<main>content — the spine reads headings from this element. Usetarget="main"(the prop defaultnullresolves to'main, article'first-match wins).
Each example below wraps the page in <x-wirekit:: and the article in <x-wirekit:: for its typography, and gives the article the wk-reading-content class, which keeps it clear of the spine from md up. The code under each preview is what the preview renders.
CSS variables
The reading-spine reads these CSS variables; override in the wrapping element's style="…" or in :root {} for a global preset:
| Variable | Default | Purpose |
|---|---|---|
--reading-spine-width-collapsed |
1.5rem |
Narrow-at-rest width (visible as a tick column) |
--reading-spine-width-expanded |
16rem |
Expanded width on hover / expand="always" |
--reading-spine-offset-top |
1rem |
boundary="container" only — pins the spine below the scroll-container top. Not used in this viewport-pinned recipe (the spine is vertically centered). |
--reading-spine-padding-y |
0.875rem |
Vertical padding inside the spine column |
--reading-spine-color-active |
var(--color-wk-text) |
Active-link color |
For the full token reference, see the reading spine's tokens.
Integration with a sticky header
If your layout has a sticky header (e.g. <x-wirekit::), keep the spine's active-link line below it with the :offset prop. The viewport-pinned spine is vertically centered, so it never sits behind the bar — but the active link is the last heading at or above a line :offset below the top of the page (6rem unless you set one). A bar taller than that hides the line, and a section highlights only after its heading has scrolled up under the bar. Give :offset at least the bar's height.
Composing with a breadcrumb
If your layout also carries a <x-wirekit::, the breadcrumb's active node and the spine's active link should reference the same logical position — both reflect "where the reader is". The breadcrumb is page-level (which page in the docs tree?); the spine is in-page (which section on the current page?).
The breadcrumb stays static for the whole page; the spine's active link updates as the reader scrolls.
The rail beside the article
When the page has a column to spare, layout="rail" puts the outline into it, open at all times:
every title on a line that bends with the indent, and a band on that line at the section the reader
is in. It stands in your grid, sticks to the top of its column from md and scrolls on its own when
the outline is taller than the window. The reading page shows it
live, with its code.
Three things make the layout:
- A grid with two columns from
md: the article, and a14.375remcolumn for the rail, such as<x-wirekit::.grid cols="1" template="md:[minmax(0,1fr)_14.375rem]"> - The rail first in the markup, placed with
md:col-start-2 md:row-start-1, so a phone that shows it (hide-below="none") reads the outline before the article. - The article in the first column with
md:col-start-1 md:row-start-1, and withoutwk-reading-content: that class reserves a gutter for the default spine, which the rail does not need.
Under a sticky header, set --reading-spine-offset-top to the header's height, so the rail sticks
below it, and pass the same height as offset, so a section counts as current once its heading
comes out from under the header.
Tips
- Use
expand="always"on dedicated docs layouts (where readers expect the TOC) instead of the defaultexpand="hover"— saves a hover-discovery moment. - Mobile users see no spine by default. The narrow-viewport experience drops the TOC; readers scroll the article without it. The progress bar at the top still works on mobile.
- For flat content (3-4 sections, all
<h2>), prefer the horizontal<x-wirekit::strip — see the marketing-landing-toc recipe.reading-toc> - For very long articles (50+ headings), the spine works but readers benefit from the
<x-wirekit::variant — a reflection of the article's structure as a vertical ruler.reading-minimap>
See also
<x-wirekit::— the sidebar primitive in detail.reading-spine> <x-wirekit::— the top-edge progress bar.reading-progress> <x-wirekit::— the one-tag composition wrapper that bundles progress + spine + bookmark with sensible defaults.reading-shell> - marketing-landing-toc recipe — the horizontal strip variant for flat marketing pages.
- long-form-article recipe — the full long-form article composition (max-width container + reading-meta + prose body).
- documentation-reader recipe — the docs-style composition: a reading shell with a minimap and a documentation-paced time-to-read meta.