How to Add a Table of Contents in Blogger Automatically (Step-by-Step 2025)
Are you looking to enhance your Blogger posts with an automatic Table of Contents that improves readability, user experience, and SEO? You’re in the right place! In this detailed tutorial, you’ll learn exactly how to add a fully automatic, clickable Table of Contents (TOC) to your Blogger posts, with no complicated manual updates each time you add a new heading. This guide is fully updated for 2025 and includes easy-to-follow instructions that anyone can implement.
Why Add an Automatic Table of Contents in Blogger?
A well-structured Table of Contents can significantly boost your blog’s usability and SEO by helping visitors quickly navigate lengthy posts and by signaling page structure to search engines. Here’s why it matters:
- Improved user navigation: Readers can jump directly to sections they care about.
- Lower bounce rates: Enhanced navigation keeps users engaged longer.
- SEO benefits: Google prefers organized pages, and TOCs help with rich snippets and featured results.
What Will This Tutorial Cover?
We’ll show you how to:
- Add the coding needed to your Blogger theme (HTML, CSS, JavaScript).
- Insert the TOC into individual posts effortlessly.
- Customize the styles to match your blog’s brand.
- Ensure your TOC works smoothly with your Blogger template.
Before You Start
Important: Always backup your Blogger theme before editing any code to prevent accidental loss or site disruptions. You can do this from Theme > Backup/Restore in the Blogger dashboard.
Step 1: Adding TOC Code to Your Blogger Theme
This step lets your Blogger blog load the necessary script and styles to generate the TOC automatically on posts where you want it.
- Log in to your Blogger dashboard.
- Go to Theme and then click the dropdown arrow next to the Customize button, and select Edit HTML.
- Scroll all the way to the bottom of the HTML editor until you find the closing
</body>
tag. - Just before the
</body>
tag, paste the following code block (this contains the CSS for styling and JavaScript logic to dynamically build the TOC):
<style>
/* Table of Contents Styles */
#blog-post-toc {
background: #f9f9f9;
border: 2px solid #ddd;
padding: 15px;
margin-bottom: 20px;
border-radius: 6px;
font-family: Arial, sans-serif;
}
#blog-post-toc h3 {
margin-top: 0;
font-weight: bold;
font-size: 1.3rem;
cursor: pointer;
color: #0074C9;
}
#blog-post-toc ol {
margin-left: 20px;
padding-left: 0;
}
#blog-post-toc ol li {
margin-bottom: 8px;
}
#blog-post-toc ol li a {
text-decoration: none;
color: #333;
}
#blog-post-toc ol li a:hover {
text-decoration: underline;
}
</style>
<script>
document.addEventListener("DOMContentLoaded", function() {
// Only run on posts
if (!document.querySelector('.post')) return;
const tocContainer = document.createElement('div');
tocContainer.id = 'blog-post-toc';
// TOC Title with toggle
const tocTitle = document.createElement('h3');
tocTitle.textContent = 'Table of Contents';
tocTitle.onclick = () => {
const ol = tocContainer.querySelector('ol');
ol.style.display = ol.style.display === 'none' ? 'block' : 'none';
};
tocContainer.appendChild(tocTitle);
// Find all H2, H3 in the post content (customize selector as needed)
const postContent = document.querySelector('.post-content');
if (!postContent) return;
const headings = postContent.querySelectorAll('h2, h3');
if (headings.length === 0) return; // No headings found
// Create TOC list
const tocList = document.createElement('ol');
headings.forEach((heading, index) => {
// Add anchor id to headings if not present
if (!heading.id) {
heading.id = 'heading-' + index;
}
const li = document.createElement('li');
// Indent h3 a bit
if (heading.tagName.toLowerCase() === 'h3') {
li.style.marginLeft = '20px';
}
const a = document.createElement('a');
a.href = '#' + heading.id;
a.textContent = heading.textContent;
li.appendChild(a);
tocList.appendChild(li);
});
tocContainer.appendChild(tocList);
// Insert TOC above the post content
postContent.parentNode.insertBefore(tocContainer, postContent);
});
</script>
Save your theme after pasting this code. What this does:
- Adds a styled TOC container
- Uses JavaScript to scan your post content’s headings (H2 and H3 by default)
- Automatically generates a clickable TOC that jumps to the corresponding section
Step 2: Prepare Your Blog Posts Headings
For the TOC to work correctly, your blog post must have proper heading tags:
- Use
<h2>
for main section titles and<h3>
for subsections. - Avoid skipping heading levels to ensure TOC hierarchy displays well.
Example:
<h2>Introduction</h2>
<p>Some intro content...</p>
<h2>Step 1: Setup</h2>
<h3>Sub-step A</h3>
<h3>Sub-step B</h3>
<h2>Conclusion</h2>
Step 3: Add TOC to Existing Posts
This solution automatically adds the TOC to every blog post with headings — no need to insert extra code in each post. Simply:
- Make sure your post uses the correct headings.
- Publish or update your post.
- Visit the post on your blog, and the TOC will appear at the top.
Step 4: Customize Your TOC
You can customize the #blog-post-toc
CSS in the theme code to match your blog’s look and feel. Some ideas:
- Change background, border colors, or font styles
- Adjust indentation for deeper heading levels
- Add smooth scrolling for anchor links using CSS
scroll-behavior: smooth;
SEO Benefits of Using a Table of Contents
An automatic TOC helps your blog rank better because:
- Clear content structure: Search engines understand your post’s hierarchy better.
- Enhanced snippet potential: Google often uses TOCs to show jump links in search results.
- Improved user engagement: Visitors stay longer and explore more sections.
Common Troubleshooting Tips
- If TOC doesn’t show, check your theme’s post container classes — update
document.querySelector('.post-content')
selector accordingly. - Make sure your headings have unique IDs (script adds them automatically if missing).
- Clear your browser cache if changes aren’t visible immediately.
Curiosity Section: What If I Want Advanced TOC Features?
Imagine adding collapsible subsections, numbered headings, or automatic highlighting as readers scroll! Advanced plugins or extra JavaScript can add these features — perfect when you want to take navigation further as your blog grows.
FAQs About Adding Table of Contents in Blogger
- Can I add the TOC to only specific posts? Yes, you can add a conditional JavaScript check or manually insert the TOC code only in selected post templates.
- Will the TOC affect my blog’s loading speed? No, the script is lightweight and loads only on blog posts, minimally affecting performance.
- Is this TOC compatible with mobile devices? Yes, the TOC is responsive and works well on desktops and mobiles.
- Can I include more heading levels like H4 or H5? Yes, just add those selectors in the JavaScript query (e.g., 'h2, h3, h4').
- How do I remove the TOC from posts that don’t need it? You can adjust the CSS to hide it or modify the script to check post labels and skip certain posts.
- Can I customize the TOC title text?
Absolutely, change the text inside the
tocTitle.textContent
line in the script. - Will internal anchor links work smoothly? Yes, clicking TOC entries scrolls smoothly to the relevant section.
- Is prior coding knowledge needed? Basic familiarity with Blogger themes helps, but the step-by-step code and instructions make it easy for anyone.
- What if my theme uses a different post content class? Inspect your post HTML structure and change the JavaScript selector to match your theme.
- Can I style the TOC to match dark mode themes? Yes, update the CSS colors accordingly to blend with dark backgrounds.
Conclusion
Adding an automatic Table of Contents in Blogger simplifies navigation for your readers, enriching user experience and boosting your SEO in the process. With just a few smart lines of code added to your theme and following proper heading structure, your blog posts become more organized and engaging. Give your readers a way to easily jump around your content today, and watch your blog’s professionalism and search rankings improve.
Remember, the best blogs are those that respect their readers’ time and attention. A well-crafted Table of Contents is a small addition with huge impact — a true win for both creators and readers alike.