Skip to content
shadcn.io

shadcn.io is not affiliated with official shadcn/ui

Scrolling Article Table of Contents Blog Block for React

A framed, fixed-height essay with six sections beside a rail that follows the section in view with a sliding bar, and a Jump to select on phones; choosing a section scrolls the essay, never the page.

Framework
UI library

Preview

Preview width

Installation

Part of Pro
Pro unlocks the code and one-line install of every Pro button and text effect, plus the MCP for your AI editor.
Have Pro already? Sign in to open it.Opens here as soon as you're Pro.

Overview

A long read with a table of contents for React with Base UI, written for Spineline, a long-form writing lab. A compact header sits over a split behind a divider: at the start a framed article of fixed height with six headings that scrolls inside its frame, and at the end a rail listing the sections. A bar slides to the section in view as you read, and "Section 3 of 6" says where you are. Choosing a section scrolls the article and nothing else, so the page never jumps. The article is a labelled, focusable scroll region that comes first in the DOM, so it can be read with a keyboard; on a phone the rail becomes a "Jump to" select above the article that follows the section in view. It uses Toc, Select and Guides, with CSS for the entrance.

FAQ

How do I use my own article?

Replace SECTIONS at the top of the file: each section has an id (the heading's anchor), a title and its paragraphs. The rail, the select, the outline passed to Toc and "Section 3 of 6" are all built from that one list, so adding a section adds it everywhere.

Why doesn't the page scroll when I choose a section?

The article is its own scroll box, and the table of contents is told to scroll that box (scrollEl) instead of the window. Selecting a section, in the rail or in the select, moves only the article. For a real post, drop the fixed height and the scrollEl, and the same rail follows the page.

How does it know which section is in view?

Toc watches the headings inside the article as you scroll and marks the one nearest the top; the first and last sections are held at the ends of the scroll. The bar is a single element that slides and resizes with a CSS transition, and it jumps without animating under reduced motion.

What replaces the rail on a phone?

A Select labelled "Jump to a section", above the article. It shows the section in view and scrolls the article when you choose another. Keyboard and screen reader users on any width can also read the article directly, since it is a focusable region with its own label.

Can I use it with a keyboard?

Yes. Tab reaches the article, where the arrow keys, Page Up and Page Down scroll it; the rail links and the select are ordinary controls, and every one shows a focus ring.

Does it work right to left?

Yes. The split, the rail's rule and the sliding bar flip to the other side, and the count is isolated with bdi.

  • Pro

    A FAQ for an object-storage service with a sticky table of contents: three topics and their questions in an outline that follows the reader, beside topic bands that each hold an accordion.

  • Pro

    A company's origin story as four long chapters of prose beside a sticky chapter index that follows the reader, turning into a row of chips on phones.

  • Pro

    Four articles you have opened as rows that lead with a progress ring, then the title, the time left and a Continue link; the header counts how many are still in progress.

  • Pro

    An annotated essay: numbered markers open a card with their note on hover and focus, jump to the note in an ordered list where the target note is tinted, and a link goes back to the exact place in the text.

  • Pro

    Post Footer Blog

    Article parts

    The end of an article: tags as links, a share cluster whose Copy link really copies, an author panel beside Published and Updated dates, and Previous and Next as two cells on a shared hairline with arrow key hints.

  • Pro

    Series Tracker Blog

    Tutorials and series

    A reader's place in a six-part series: the catalog's vertical Steps with a tick for each part read, the current part's panel with a typographic cover, a thin progress bar and a Shine Button that continues to the next part.