karsttech.com/content/personal-blog/toc-disable-example/index.md

1.6 KiB

title description date draft categories tags disableToc
TOC Disable Example Example showing how to disable the table of contents in markdown files 2025-01-27 false
examples
toc
markdown
hugo
true

{{< lead >}} This page demonstrates how to disable the table of contents in markdown files. {{< /lead >}}

How to Disable TOC

To disable the table of contents in any markdown file (including index.md files), simply add the disableToc: true parameter to the front matter:

---
title: "Your Page Title"
description: "Your page description"
disableToc: true  # This disables the TOC
---

Usage Examples

For Individual Pages

Add disableToc: true to the front matter of any markdown file to disable the TOC for that specific page.

For Index Pages

For index.md files that serve as list pages, you can also use the cascade parameter to apply the setting to all pages in that section:

---
title: "Section Title"
cascade:
  disableToc: true  # Disables TOC for all pages in this section
---

How It Works

When disableToc: true is set:

  1. The table of contents will not be displayed on the page
  2. The TOC JavaScript will not be loaded (improving performance)
  3. The TOC highlighting functionality will be disabled

Note

This feature works for both:

  • Individual article pages (using the single.html template)
  • List/index pages (using the list.html template)

The TOC will still be generated by Hugo, but it won't be displayed or have JavaScript functionality when disabled.