<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/table-of-contents-web-component-zachleat-com-toxhjyu8k" -->

---
title: Table of Contents Web Component—zachleat.com | daily.dev
description: A zero-dependency web component progressively enhances server-rendered ordered or unordered lists into a table of contents that highlights headings currently...
canonical: https://daily.dev/posts/table-of-contents-web-component-zachleat-com-toxhjyu8k
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Table of Contents Web Component—zachleat.com | daily.dev
og:description: A zero-dependency web component progressively enhances server-rendered ordered or unordered lists into a table of contents that highlights headings currently...
og:url: https://daily.dev/posts/table-of-contents-web-component-zachleat-com-toxhjyu8k
og:image: https://api.daily.dev/og/posts/tOxHjYU8k.png
og:image:alt: Table of Contents Web Component—zachleat.com
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Table of Contents Web Component—zachleat.com

**[Zach Leatherman](https://daily.dev/sources/zachleat)** · 2 min read · 6 upvotes · 0 comments

## Summary

A zero-dependency web component progressively enhances server-rendered ordered or unordered lists into a table of contents that highlights headings currently visible in the viewport, or client-renders the list if none exists. Extracted from the WebC Tugboat starter project's table-of-contents.webc component for standalone use, it ships with no component CSS, is configured via a selector attribute (defaulting to main headings h2 through h6), and is installable via npm.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://www.zachleat.com/web/table-of-contents>

## Questions this post answers

### How can I create a table of contents web component that highlights the currently visible heading in the viewport?

The @zachleat/table-of-contents package is a zero-dependency, zero-CSS web component that progressively enhances existing server-rendered ol or ul heading lists, or client-renders them if absent, and highlights whichever section is currently visible in the viewport. It accepts a selector attribute to scope which headings are collected, defaulting to main :is(h2, h3, h4, h5, h6), and is installed via npm install @zachleat/table-of-contents.

_daily.dev surfaces web component releases like this for developers building accessible page navigation._

## Similar posts on daily.dev

- [Automatic Table of Contents with Eleventy](https://daily.dev/posts/automatic-table-of-contents-with-eleventy-byabbfrwi) · Kitty says hi. · 2 upvotes · 0 comments
- [How we built the new Table of Contents feature](https://daily.dev/posts/how-we-built-the-new-table-of-contents-feature-ywsatilgk) · Medium · 3 upvotes · 0 comments
- [How to Create a Table of Contents for Your Article](https://daily.dev/posts/how-to-create-a-table-of-contents-for-your-article-torimoag6) · freeCodeCamp · 1 upvotes · 0 comments
- [Tabbed Interface: The Web Component :: Aaron Gustafson](https://daily.dev/posts/tabbed-interface-the-web-component-aaron-gustafson-5ynmkmisp) · Aaron Gustafson · 0 upvotes · 0 comments

---

Tags: [#javascript](https://daily.dev/tags/javascript), [#npm](https://daily.dev/tags/npm), [#web-components](https://daily.dev/tags/web-components)

[View this post on daily.dev](https://daily.dev/posts/table-of-contents-web-component-zachleat-com-toxhjyu8k)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Table of Contents Web Component—zachleat.com","url":"https://daily.dev/posts/table-of-contents-web-component-zachleat-com-toxhjyu8k","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/table-of-contents-web-component-zachleat-com-toxhjyu8k"},"datePublished":"2026-09-15T14:25:43.004Z","dateModified":"2026-09-15T14:26:02.952Z","description":"A zero-dependency web component progressively enhances server-rendered ordered or unordered lists into a table of contents that highlights headings currently...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/7ac1660d2cfce252f24b2cf70f3abb2a?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/7ac1660d2cfce252f24b2cf70f3abb2a?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"Zach Leatherman","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Zach Leatherman","logo":"https://media.daily.dev/image/upload/t_logo,f_auto/v1/logos/7ce10e5a06b74735aa2b19fa200414bf","url":"https://daily.dev/sources/zachleat"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/table-of-contents-web-component-zachleat-com-toxhjyu8k","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":6},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"javascript,npm,web-components","timeRequired":"PT2M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Zach Leatherman","item":"https://daily.dev/sources/zachleat"},{"@type":"ListItem","position":3,"name":"Table of Contents Web Component—zachleat.com"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/table-of-contents-web-component-zachleat-com-toxhjyu8k#faq","mainEntity":[{"@type":"Question","name":"How can I create a table of contents web component that highlights the currently visible heading in the viewport?","acceptedAnswer":{"@type":"Answer","text":"The @zachleat/table-of-contents package is a zero-dependency, zero-CSS web component that progressively enhances existing server-rendered ol or ul heading lists, or client-renders them if absent, and highlights whichever section is currently visible in the viewport. It accepts a selector attribute to scope which headings are collected, defaulting to main :is(h2, h3, h4, h5, h6), and is installed via npm install @zachleat/table-of-contents. daily.dev surfaces web component releases like this for developers building accessible page navigation."}}]}
```

