How to Add an Automatic Table of Contents to Blogger: A Complete Step-by-Step Guide

In the world of SEO and Web Development, user experience is king. A Table of Contents (TOC) not only helps readers navigate long-form articles but also helps search engines like Google display 'jump-to' links in search results. For Blogger users, this isn't a native feature, so we must implement it using HTML, CSS, and JavaScript.

Step 1: Backup Your Blogger Template

Before modifying any code, it is crucial to back up your theme. Go to your Blogger Dashboard, select Theme, click the dropdown menu next to 'Customize', and select Backup. This ensures you can restore your site if anything goes wrong during the customization process.

Step 2: Add the CSS Styling

To make the Table of Contents look professional, you need to add custom CSS. Go to Theme > Edit HTML and search for the </b:skin> or </style> tag. Paste the following CSS code directly above it:

#mbt-toc { background-color: #f8f9fa; border: 1px solid #dee2e6; padding: 15px; margin-bottom: 20px; display: table; border-radius: 5px; }
#mbt-toc b { font-size: 18px; color: #333; }
#mbt-toc ul { list-style-type: none; margin: 10px 0 0 0; padding: 0; }
#mbt-toc li { margin-bottom: 5px; }
#mbt-toc a { text-decoration: none; color: #007bff; }
#mbt-toc a:hover { text-decoration: underline; }

Step 3: Insert the JavaScript Logic

Now, we need JavaScript to automatically detect your headings (H2 and H3) and generate the list. Scroll to the bottom of your HTML and paste this script just before the closing </body> tag:

Note: This script scans the post body for

and

tags, creates unique IDs for them, and populates the TOC container.

Step 4: Add the TOC Container to Your Posts

To display the Table of Contents in a specific post, switch from Compose View to HTML View in the Blogger post editor. Paste the following HTML code where you want the TOC to appear (usually after the first paragraph):

<div id="mbt-toc"><b>Table of Contents</b></div>

Step 5: Ensure Your Headings are Correct

For the script to work, ensure your subheadings in the post are set as 'Heading' (H2) or 'Subheading' (H3). The JavaScript will ignore 'Normal' text or bolded lines. Once you publish the post, the script will automatically crawl those headings and build your functional, clickable Table of Contents.

Conclusion

Adding a TOC to your Blogger template is a powerful way to improve dwell time and SEO rankings. By following this guide, you have successfully added a professional, automated feature to your blog without needing expensive plugins or heavy frameworks.


💡 Pro Tip: Keep your software updated to avoid these issues in the future.


Category: #Website