How to Format an Automatic Table of Contents

Johnny Jul 09, 2026

Creating an automatic table of contents (TOC) can significantly enhance the readability and navigability of your long documents. This guide will walk you through the process of formatting an automatic TOC using HTML and CSS, ensuring your TOC is well-structured, visually appealing, and easy to use.

Excel Table of Contents that Automatically Updates - Excel Campus
Excel Table of Contents that Automatically Updates - Excel Campus

Before we dive in, let's clarify what we mean by "automatic." In this context, "automatic" refers to a TOC that updates itself as you add, remove, or reorganize sections in your document. This is achieved using HTML headings and CSS.

How To Create A Clickable Table Of Contents For Your Ebook
How To Create A Clickable Table Of Contents For Your Ebook

Understanding HTML Headings

HTML headings, denoted by the

to

tags, are the backbone of an automatic TOC. They not only structure your content but also provide the necessary information for the TOC to function.

Creating Microsoft Word Table of Contents Automatically
Creating Microsoft Word Table of Contents Automatically

For a TOC, we'll primarily use

,

, and

tags.

tags represent major sections,

tags represent sub-sections, and

tags represent sub-sub-sections. This hierarchy allows us to create a multi-level TOC.

Setting Up Your HTML

How to Create a Table of Contents in Word
How to Create a Table of Contents in Word

First, ensure your HTML document is set up correctly. The basic structure looks like this:

<!DOCTYPE html>
<html>
<head>
</head>
<body>
</body>
</html>

We'll add our content and TOC within the tags.

Creating the TOC

How to create an automatic table of contents in Word 2019
How to create an automatic table of contents in Word 2019

To create the TOC, we'll use an unordered list (

    ) with list items (
  • ). Each list item will correspond to a heading in your document. Here's a basic example:

<ul id="toc">
  <li><a href="#section1">Section 1</a></li>
  <li><a href="#section2">Section 2</a></li>
</ul>

The tags within each

  • serve as links to their respective sections. The href attribute of each tag should match the id of the corresponding heading.

  • How to Create a Table of Contents in Word and Update it? | IT4nextgen
    How to Create a Table of Contents in Word and Update it? | IT4nextgen
    Creating a Table of Contents in Word 2016 for Mac (see note below for Headings video link)
    Creating a Table of Contents in Word 2016 for Mac (see note below for Headings video link)
    How to make a table of contents in word
    How to make a table of contents in word
    Dissertation Help: How to format your Table of Contents
    Dissertation Help: How to format your Table of Contents
    How to create an automatic table of contents in Microsoft Word
    How to create an automatic table of contents in Microsoft Word
    Using the Table of Contents worksheet
    Using the Table of Contents worksheet
    Modify your MS Word Table of Contents formatting
    Modify your MS Word Table of Contents formatting
    Google Docs can make a table of contents for you — here’s how
    Google Docs can make a table of contents for you — here’s how
    How to Automatically Resize a Table in Microsoft Word
    How to Automatically Resize a Table in Microsoft Word
    Word Tab Index Page - 7 Free PDF Printables | Printablee
    Word Tab Index Page - 7 Free PDF Printables | Printablee
    How to Create a Table of Contents in OpenOffice/LibreOffice
    How to Create a Table of Contents in OpenOffice/LibreOffice
    How to insert a table of contents manually in Word
    How to insert a table of contents manually in Word
    How To Create A Table Of Contents In Microsoft Word
    How To Create A Table Of Contents In Microsoft Word
    OpenOffice Tutorial: How to Create a Table of Contents
    OpenOffice Tutorial: How to Create a Table of Contents
    the table of contents is shown with an arrow pointing to it
    the table of contents is shown with an arrow pointing to it
    How To Create a Clickable Table of Contents in Microsoft Word
    How To Create a Clickable Table of Contents in Microsoft Word
    How to Create a Table of Contents in Microsoft Word
    How to Create a Table of Contents in Microsoft Word
    Here's the Easy Way to Insert a Table of Contents in Microsoft Word
    Here's the Easy Way to Insert a Table of Contents in Microsoft Word
    Table of Contents and Index: Two ways to help readers find their way
    Table of Contents and Index: Two ways to help readers find their way
    20+ Table of Contents Template | Mous Syusa
    20+ Table of Contents Template | Mous Syusa
    Four Effective Methods to Add a Table of Contents to a PDF
    Four Effective Methods to Add a Table of Contents to a PDF