Hugo themes with dynamic TOC highlighting

@huyingjie posted a question earlier:

I like table of contents in the sidebar, such as, . When I scroll down, the table of contents changes. How can I achieve this in Hugo?

to which I replied:

On your current website generated with Hexo with the NexT theme, the Bootstrap Scrollspy plugin is being used. Look for the file js/src/scrollspy.js on your website.

Also, see a demonstration of Bootstrap Scrollspy here:

Since this is pure CSS and JavaScript, it is independent of the static-website-generator (Hexo or Hugo) but rather on the theme itself, in this case, the “hexo-next-theme”.

It turns out that some of the Hugo themes have already implemented similar dynamic TOC highlighting, examples include:

  1. Academic, see
  2. Material Docs, see
  3. DocuAPI, see

Though of course, it is understandable that @huyingjie would like something more similar to the existing Hexo “NexT” theme.

It turns out there have been two efforts to port the NexT theme to Hugo:

@leopku’s version is rather outdated now.

@xtfly’s version has the same look-and-feel of the original Hexo NexT theme, though it has started to lag behind too. The main thing though is that dynamic TOC highlighting does not yet work, and is listed as a TODO on

NexT seems to be the most popular Hexo theme according to, so perhaps it would be an interesting project to port this beautiful theme to Hugo with all the functionalities? :wink:

@huyingjie wrote:

@anthonyfok Thank you. Academic theme does not have table of contents sidebar

The default Academic theme doesn’t, but its documentation does! And it turns out it is easy to copy the table of content sidebar to your Hugo website when using the Academic theme:

Initial preparation

  1. Run git clone --recurse-submodules to get the Academic documentation website (this has the TOC sidebar in docs/)
  2. Run git clone --recurse-submodules to get the Academic kickstart (plain vanilla but fully configured Academic theme).
  3. Run cd academic-kickstart,
  4. Run hugo new post
  5. Edit content/post/ in your favorite editor.
  6. Run hugo server and navigate to the post that you just created. Note that there is no TOC sidebar.

Now, do the magic

Staying inside the academic-kickstart directory:

  1. mkdir layouts
  2. cp -avi ../academic-www/layouts/docs layouts/post (for the single.html template)
  3. cp -avi ../academic-www/layouts/partials/ layouts/
  4. cp -avi ../academic-www/static/css/ static/ which copies static/css/custom.css for the TOC highlighting magic
  5. Edit config.toml, search for custom_css = [] and change it to custom_css = ["custom.css"]

And that should do the trick!

1 Like

For those who are too busy to follow the steps above, check out

which is based on
and as described above.

Please be sure to add the --recurse-submodules flag when you clone the repository, like so:

git clone --recurse-submodules \

so that the base Academic theme is fetched properly.

After running hugo server, you’ll find the example with dynamic TOC at http://localhost:1313/post/toc-test/

This example uses the Hugo Academic theme which currently uses Bootstrap v3.3.7 with ScrollSpy. The same dynamic TOC effect probably originated from Bootstrap v3.3.x documentation itself, see