The table of contents component helps users understand the content and the structure of a web page and lets users looking for something specific navigate quickly to a specific section of the web page.
Use the table of contents component on a web page when:
Do not use the table of contents component on a web page when:
The table of contents component is a list of anchor links. Each anchor link points to a section within the web page. The sections typically have a clear title (typically h2 headings). The titles of the sections are used as the link text for the anchor links.
On desktop and tablet resolutions, the anchor links are shown in a horizontal way with a separator between them. When necessary, the anchor links are wrapped to new lines.
On mobile resolutions, the anchor links are shown in a vertical way.
<nav class="table-of-contents" aria-labelledby="table-of-contents-header">
<div class="content-container">
<h2 id="table-of-contents-header" class="visually-hidden">Table of content</h2>
{% include '@list' with {
'type': 'links',
'items': list,
'modifier': 'inline'
} %}
</div>
</nav>
<nav class="table-of-contents" aria-labelledby="table-of-contents-header">
<div class="content-container">
<h2 id="table-of-contents-header" class="visually-hidden">Table of content</h2>
<ul class="inline">
<li><a href="#" class="active">Anchor link 1</a></li>
<li><a href="#">Anchor link 2</a></li>
<li><a href="#">Anchor link 3</a></li>
<li><a href="#">Anchor link 4</a></li>
</ul>
</div>
</nav>
{
"list": [
"<a href=\"#\" class=\"active\">Anchor link 1</a>",
"<a href=\"#\">Anchor link 2</a>",
"<a href=\"#\">Anchor link 3</a>",
"<a href=\"#\">Anchor link 4</a>"
]
}
.table-of-contents {
margin-bottom: 2rem;
ul > li {
display: block;
width: 100%;
margin-right: 0;
@include phablet {
display: inline-block;
width: auto;
}
&::after {
@include phablet {
@include theme('color', 'color-primary--lighten-3', 'filter-nav-longdash-color');
display: inline-block;
padding: 0 .2rem;
content: '—';
}
}
&:last-child::after {
content: '';
}
}
}