Add a table of contents to your post
You can build a table of contents by adding ‘anchors’ to headings in your post and then creating a list of links to those anchors.
See an example of this in action at the top of this discussion and in the Restart Party Kit (in English).
1. Add anchors to headings
-
Add this code just before the headings you want to link to:
<h1 id="heading--title1">
(note: you should replacetitle1
with a word that describes the heading, e.g.intro
- this should be different for every anchor you create.) -
And add this code just after it:
</h1>
So, the headings you want to link to should look something like this:
<h1 id="heading--title1">Your first heading</h1>
<h1 id="heading--title2">Your second heading</h1>
This produces the following:
Your first heading
Your second heading
You can do the same for subheadings:
<h1>
is the biggest heading (in terms of font size), but you can also use <h2>
and <h3>
tags for subheadings. E.g.:
<h2 id="heading--subtitle1">Your first subheading</h2>
<h3 id="heading--subtitle2">Your second subheading</h3>
Produces…
Your first subheading
Your second subheading
2. Create links to headings
You can link to a heading with an anchor (e.g. to build a table of contents) by formatting text as a link in the usual way, but instead of a URL, add the id
of the anchor, such as #heading--title1
.
E.g.:
1. [Your first heading](#heading--title1)
2. [Your second heading](#heading--title2)
This produces the following: