b2KIT

Table of Contents Generator

Generate HTML table of contents from heading structure with anchor links, nesting, and numbering options.

Tested tool guide Tested browser tools Checked August 16, 2026

What Table of Contents Generator does, with a checked example

Paste HTML that contains headings and this tool returns a ready-to-use table of contents: a nested list that mirrors the document's h1-h6 outline, where each entry links to its heading's id anchor and can carry a decimal number (1.1, 1.2.1). It runs entirely in the browser, so nothing you paste is sent to a server. The thing most people get wrong: the links only work in a page whose headings actually have the id attributes the entries point to, and the TOC only covers the headings in the snippet you paste, not the whole file.

Worked example

A concrete input and expected output from the current implementation.

Input

<h1 id="introduction">Introduction</h1>
<h2 id="install">Installation</h2>
<h2 id="usage">Usage</h2>
<h3 id="config">Configuration</h3>
<h1 id="reference">Reference</h1>
<h2 id="options">Options</h2>

Expected output

<ul>
  <li><a href="#introduction">1. Introduction</a>
    <ul>
      <li><a href="#install">1.1 Installation</a></li>
      <li><a href="#usage">1.2 Usage</a>
        <ul>
          <li><a href="#config">1.2.1 Configuration</a></li>
        </ul>
      </li>
    </ul>
  </li>
  <li><a href="#reference">2. Reference</a>
    <ul>
      <li><a href="#options">2.1 Options</a></li>
    </ul>
  </li>
</ul>

The tool walks the pasted headings in document order, nesting each one under the nearest preceding heading of a shallower level, and assigns decimal numbers by position: 1, then 1.1 and 1.2, with the h3 under "Usage" becoming 1.2.1. Each link points to its heading's id attribute, which is why the sample headings carry ids.

How the result is produced

1

How the outline is built

The tool scans the pasted HTML for h1 through h6 elements in document order and records each heading's text and its id attribute. The TOC's shape comes from heading levels alone: an h3 following an h2 becomes a nested child of that h2, an h1 starts a new top-level entry. Headings that are not present in the paste cannot appear, so the outline matches exactly what you give it.

2

Links and numbering

Every entry is an anchor element whose href targets the id of its heading, so the TOC works only where those ids exist on the page. With numbering enabled, each entry gets a decimal number computed from its position: top-level headings count 1, 2, 3, each nested level appends its own counter (1.2.1), and the count restarts under every top-level heading. Numbers describe position in the outline, not anything in the heading text.

Good uses

  • Adding a jump list to a long documentation page or article so readers can move between sections without scrolling.
  • Producing a page or site index from an existing HTML page instead of hand-writing nested lists.
  • Reviewing a page's heading hierarchy at a glance to spot skipped levels or a flat, undifferentiated structure before publishing.

Limits and checks

  • Links work only if the target page's headings carry the id attributes the links reference; headings pasted without ids yield entries whose hrefs have no matching element, and clicking them does nothing.
  • The TOC reflects exactly the HTML you paste. Paste a fragment that starts at h2 and the first entry sits at the top level with no h1 above it; the nesting tree is only as complete as your input.
  • Decimal numbers are assigned by position at generation time. Reordering headings and regenerating changes all downstream numbers, and if heading text already contains manual numbers like "3. Introduction", the two sets of numbers can disagree.

Common questions

I pasted the generated TOC into my page but the links don't scroll anywhere. Why?

Anchor links only work when the page contains an element whose id matches the href. The TOC targets the id attributes of the headings you pasted, so if your document's headings lack those ids, or use different ones, the click has nowhere to go. Compare each href to the ids on the page and add matching ids to the headings.

Can it read headings from a Markdown document?

Not directly, no. The tool reads heading elements from the HTML you paste, and Markdown markers like ## Title are not HTML headings, so nothing would be detected. Convert the Markdown to HTML first, or paste the rendered page, and then generate the TOC from that.

References and verification

The example and behavioral notes were checked against the browser implementation. Standards and primary references below define the relevant format, formula, or platform behavior.

Related Tools