Blog · Gutenberg

Table of Contents block for WordPress

Auto-generated table of contents from headings on the page, with smooth scroll and active-link highlighting.

Get Blockenberg

Free Gutenberg block in Blockenberg. The inspector controls and front-end behavior on this page come from this block’s source, not a shared stub.

Get Blockenberg

What it actually does

Auto-generated table of contents from headings on the page, with smooth scroll and active-link highlighting.

Inspector panels on this block: Heading Levels, Behaviour, Size & Layout. Those titles come from index.js, not from a shared template.

Behavior controls: “List Style” options: None, Bullets, Numbers.

Where to find it

Gutenberg inserter → Blog → search “Table of Contents” (block name `blockenberg/table-of-contents` in block.json). Style it in the sidebar after insert.

How to use Table of Contents block for WordPress

  1. Install Blockenberg. Install from WordPress.org and activate the plugin.
  2. Insert the block. Edit a page, click +, search for “Table of Contents”, insert it. Category: Blog.
  3. Configure inspector controls that exist on this block. Open Heading Levels. Set “H2”, “H3”, “H4”, “H5”.
  4. Check the published page. The view script reads HTML data attributes: data-collapsed, data-include, data-indent, data-list-style, data-max-height, data-offset, data-smooth. The block editor preview may not run the same view script.

Inspector controls from this block’s code

ControlWhat the code does
H2On/off toggle in the inspector. On by default. Saved as `includeH2`.
H3On/off toggle in the inspector. On by default. Saved as `includeH3`.
H4On/off toggle in the inspector. Off by default. Saved as `includeH4`.
H5On/off toggle in the inspector. Off by default. Saved as `includeH5`.
H6On/off toggle in the inspector. Off by default. Saved as `includeH6`.
TOC TitleText field in the inspector. block.json default: Table of Contents. Saved as `tocTitle`.
CollapsibleOn/off toggle in the inspector. On by default. Saved as `collapsible`.
Collapsed by DefaultOn/off toggle in the inspector. Off by default. Saved as `defaultCollapsed`.
Smooth ScrollOn/off toggle in the inspector. On by default. Saved as `smoothScroll`.
Scroll Offset (px) — for fixed headersNumeric range control in the inspector. Range 0–200. block.json default: 80. Saved as `scrollOffset`.
Sticky PositionOn/off toggle in the inspector. Off by default. Saved as `sticky`.
Indent Nested LevelsOn/off toggle in the inspector. On by default. Saved as `indentNested`.
List StyleSelect control; the chosen value is saved on the block. Options: None; Bullets; Numbers. block.json default: none. Saved as `listStyle`.
Max Width (0 = full)Numeric range control in the inspector. Range 0–900. block.json default: 0. Saved as `maxWidth`.
Max Height — scroll inside (0 = none)Numeric range control in the inspector. Range 0–800. block.json default: 0. Saved as `maxHeight`.
Padding (px)Numeric range control in the inspector. Range 0–60. block.json default: 20. Saved as `padding`.
Border Radius (px)Numeric range control in the inspector. Range 0–24. block.json default: 8. Saved as `borderRadius`.

What the front-end script actually does

When this is the right block

Notes from the implementation

viewScript: this folder’s frontend.js is enqueued on the front end for this block.

FAQ

How do I add the Table of Contents block in WordPress?

Install Blockenberg from WordPress.org, edit a page in the block editor, click +, and search for “Table of Contents”. It sits under Blog. After insert, open Heading Levels and set “H2”, “H3”, “H4”, “H5”.

What makes Table of Contents different from other Blockenberg blocks?

Auto-generated table of contents from headings on the page, with smooth scroll and active-link highlighting. Inspector labels on this block include “H2”, “H3”, “H4”, “H5”.

Is the Table of Contents Gutenberg block free?

Yes. Table of Contents ships inside Blockenberg. Get the plugin from WordPress.org — no paid add-on is required for this block.

Can I style Table of Contents to match my theme?

Yes. Blockenberg’s shared typography and color panels apply here, plus any block-specific style controls listed on this page (panels: Heading Levels, Behaviour, Size & Layout).

Related blog blocks

Get Blockenberg

Install Blockenberg from WordPress.org, then insert Table of Contents from the Gutenberg inserter.

Get Blockenberg