# Table of Contents

> A docs-style "On this page" list with automatic 1, 1.1, 1.2 numbering from CSS counters.

- Category: [CSS Navigation](https://copy-css.com/category/navigation)
- Tags: toc, contents, counters, docs, sidebar, numbered
- Live preview: https://copy-css.com/snippets/table-of-contents
- License: Free for personal and commercial use. No signup, no attribution required.

## HTML

```html
<nav class="toc" aria-label="On this page">
  <ol>
    <li><a href="#">Getting started</a>
      <ol>
        <li><a href="#" aria-current="true">Install</a></li>
        <li><a href="#">Configure</a></li>
      </ol>
    </li>
    <li><a href="#">Usage</a></li>
    <li><a href="#">FAQ</a></li>
  </ol>
</nav>
```

## CSS

```css
.toc {
  font: 14px/1.4 system-ui, sans-serif;
}

.toc ol {
  margin: 0;
  padding: 0;
  list-style: none;
  counter-reset: toc;
}

.toc li {
  counter-increment: toc;
}

.toc a {
  display: flex;
  gap: 8px;
  padding: 5px 14px;
  border-left: 2px solid #e4e4e7;
  color: #52525b;
  text-decoration: none;
  transition: color 0.2s ease, border-color 0.2s ease;
}

/* 1, 1.1, 1.2, 2 ... */
.toc a::before {
  content: counters(toc, ".");
  color: #a1a1aa;
  font-variant-numeric: tabular-nums;
}

.toc ol ol a {
  padding-left: 28px;
}

.toc a:hover {
  color: #18181b;
}

.toc a[aria-current] {
  border-color: #2563eb;
  color: #2563eb;
  font-weight: 600;
}

.toc a[aria-current]::before {
  color: inherit;
}
```

## Notes

- This CSS Table of Contents is 49 lines of pure CSS (0.7 KB) with no JavaScript and no dependencies. It uses transitions and Flexbox.
- In JSX use `className` instead of `class`. In Tailwind projects put the CSS in the global stylesheet.
