We use cookies to ensure you get the best experience on our website. Read our privacy policy

Skip to main content

Directory

Table of Contents

A dynamic, interactive table of contents component that automatically generates navigation from your page headings. Perfect for long-form content, documentation, and articles that need clear structure and easy navigation.

  • Check Circle

    Auto-highlighting: Current section is highlighted during scroll

  • Check Circle

    Smooth Scrolling: Click navigation with smooth transitions

  • Check Circle

    Responsive Design: Adapts to different screen sizes

  • Check Circle

    Accessibility: Semantic markup with ARIA support

page.astro
---
const headings = await getHeadings(); // Get from your content
---
<TOC {headings} depth={3} title="On This Page" />

Choose how deep your table of contents should go (1-6 levels):

---
<TOC
headings={[
{ depth: 1, slug: '#example-1', text: 'H1 Heading' },
{ depth: 2, slug: '#example-2', text: 'H2 Heading' },
{ depth: 3, slug: '#example-3', text: 'H3 Heading' },
]}
depth={3}
title="Three Levels Deep"
/>

Track reading progress with an optional progress bar:

The progress bar can track either:

  • Overall page scroll progress
  • Specific content section progress using the contentSelector prop

Specify a content section to track:

<TOC
headings={headings}
contentSelector=".article-content"
progressBar={true}
/>

This is useful when you want the TOC to track a specific content area rather than the entire page.

Position your TOC to match your layout:

Table of Contents Component Props Extends <div> HTMLElement
Prop Type Default Description
headings MarkdownHeading[] [] Array of heading objects from your content
depth number 3 Maximum heading depth to display (1-6)
showBreak boolean false Show separators between different heading depth
title string Table of Contents Custom title for the TOC
align left | right left Horizontal alignment of the TOC
variant default | card default Style variant of the TOC
indent boolean true Indent the TOC items by the heading depth
progressBar boolean false Show a progress bar indicating reading progress
contentSelector string undefined CSS selector for the content section to track
---
export async function getStaticPaths() {
const posts = (await getCollection('docs')).map((post) => {
return {
params: { slug: post.slug },
props: { post },
};
});
return posts;
}
const { post } = Astro.props;
const { Content, headings } = await post.render();
---
<TOC headings={headings} depth={3} title="On This Page" />
Documentation pages
Long-form articles
Tutorial content

Limited Time Launch Sale

Ready to improve your content navigation? Get our AstroJS starter template now and implement the Table of Contents component in minutes.

GET 60% OFF!
North Star Themes Logo

Subscribe to our newsletter

Get the latest AstroJS tips and tricks right to your inbox

Email: [email protected]

© 2025 North Star Themes

Web Kit Provided By North Star Themes