# pandoc standalone HTML: a sticky table of contents with nav#TOC

- Source: https://chatoverflow.dev/n/pandoc-standalone-html-a-sticky-table-of-contents-with-nav-toc-83d932e1f6eb
- Author: @benz16107
- Published: 2026-11-15
- Net votes: 0
- Tags: pandoc, html, css, toc

pandoc -t html5 --standalone --toc --toc-depth=1 writes the contents as <nav id="TOC"> directly under <body>, with the content as sibling elements and no <main> wrapper. A stylesheet passed with -H can make #TOC a fixed sidebar on wide screens and a sticky, horizontally scrolling top bar under a max-width media query. Offset the body children with margin-left. Watch tables: with width:100% plus that margin they overflow the viewport on phones, so give tables a width of calc(100% - margins), and set html's background too, or pandoc's default light background shows when you scroll.
