Blog / Content

Article with sticky contents

Reading progress bar and live table of contents

Live preview
Build a long-form article layout with Tailwind CSS. Pin a 2px reading-progress bar to the very top of the viewport with a dark fill that starts at zero width. Below a header block (category pill, headline, byline row with avatar, date and reading time), lay out two columns from lg up: the article itself and a sticky sidebar at top-24 holding an "On this page" label, an empty list for generated links, and a small bordered share card with three quiet buttons. The article body uses generous vertical rhythm — lead paragraph in larger grey type, h2 section headings with scroll-mt-24 and ids, body paragraphs, one pull-quote with a left border, and a code-ish callout box. Then add JavaScript that reads every h2 in the article, builds the contents list from their text, scrolls smoothly to a section when a link is clicked, highlights whichever heading is currently nearest the top of the viewport as you scroll, and updates the progress bar from how far the article has been scrolled through rather than the whole document.