Modern Table of Contents (Right Menu) Styling
Overview
Enhanced the right-side Table of Contents (TOC) menu with modern, professional styling and interactive features.
Features Implemented
🎨 Visual Enhancements
- Clean White Background - Matches left sidebar design
- Border & Shadow - Subtle left border and shadow for depth
- “On This Page” Header - Purple underline accent
- Hover Effects - Smooth color transitions and movement
- Active Section Highlighting - Purple accent on current section
- Reading Progress Dots - Visual indicators for each heading
- Nested Indentation - Clear hierarchy for H2, H3, H4, etc.
🚀 Interactive Features
- Auto-Highlight on Scroll - JavaScript automatically highlights current section
- Smooth Scrolling - Click TOC links for smooth page navigation
- Auto-Scroll TOC - TOC scrolls to show active link
- Reading Progress Bar - Visual indicator of page progress
- Hover Arrows - Right arrow appears on hover
📱 Responsive Design
| Screen Size | Behavior |
|---|---|
| < 1200px | Hidden (mobile/small tablets) |
| 1201-1400px | Compact mode (14rem width) |
| 1401-1919px | Standard mode (16rem width) |
| 1920px+ | Expanded mode (18rem width) |
♿ Accessibility
- Keyboard Navigation - Full keyboard support
- Focus Indicators - Clear focus outlines
- ARIA Labels -
aria-current="true"for active links - High Contrast Mode - Enhanced borders and backgrounds
- Reduced Motion - Respects user preferences
- Screen Reader Friendly - Semantic HTML structure
File Structure
docs-hugo/
├── static/
│ ├── css/
│ │ └── modern-toc.css # TOC styling (8KB)
│ └── js/
│ └── modern-toc.js # Active highlighting (5KB)
└── layouts/
└── partials/
└── docs/
└── inject/
└── head.html # Import CSS/JS
CSS Classes
Main Classes
.book-toc- Main TOC container.book-toc nav- TOC navigation wrapper.book-toc nav ul- List containers.book-toc nav ul a- TOC links
State Classes
.active- Currently visible section.compact- Compact mode (optional).expanded- Expanded mode (optional)
Pseudo-elements
::before- “On This Page” header and progress indicator::after- Hover arrow
Color Scheme
| Element | Color | Usage |
|---|---|---|
| Background | #ffffff | Main background |
| Border | #e8e8e8 | Separators |
| Text | #555 | Default links |
| Hover | #667eea | Interactive states |
| Active | #667eea | Current section |
| Nested | #666 / #777 | Subdued hierarchy |
JavaScript Features
Auto-Highlighting
// Automatically highlights section as user scrolls
config.offset = 100; // Pixels from top to trigger
Smooth Scrolling
// Click TOC links for smooth navigation
config.smoothScroll = true;
Reading Progress
// Visual progress bar showing page completion
addReadingProgress();
Customization
Change Header Text
.book-toc nav > ul:first-child::before {
content: 'Table of Contents'; /* Change this */
}
Change Active Color
.book-toc nav ul a.active {
color: #your-color;
border-left-color: #your-color;
}
Adjust Spacing
.book-toc nav ul li {
margin: 0.5rem 0; /* Adjust this */
}
Change Offset for Active Highlighting
// In modern-toc.js
const config = {
offset: 150, // Increase/decrease as needed
};
Usage Examples
Standard TOC
<!-- Automatically generated by Hugo -->
<aside class="book-toc">
<nav>
<ul>
<li><a href="#heading-1">Heading 1</a></li>
<li><a href="#heading-2">Heading 2</a>
<ul>
<li><a href="#subheading">Subheading</a></li>
</ul>
</li>
</ul>
</nav>
</aside>
With Custom Classes
<aside class="book-toc compact">
<!-- More condensed spacing -->
</aside>
<aside class="book-toc expanded">
<!-- More spacious layout -->
</aside>
Browser Support
✅ Chrome/Edge 90+
✅ Firefox 88+
✅ Safari 14+
✅ Opera 76+
✅ Mobile browsers (iOS Safari, Chrome Mobile)
Performance
- CSS Size: ~8KB (minified ~5KB)
- JS Size: ~5KB (minified ~2KB)
- Load Time: < 50ms
- Render Impact: Minimal
- No Dependencies: Pure CSS/JS
Features Comparison
| Feature | Before | After |
|---|---|---|
| Visual Style | Basic list | Modern design |
| Active Highlighting | Manual | Automatic |
| Smooth Scrolling | Browser default | Enhanced |
| Progress Indicator | None | Visual bar |
| Responsive | Fixed width | Adaptive |
| Accessibility | Basic | Enhanced |
| Hover Effects | None | Smooth transitions |
Dark Mode Support
The TOC includes dark mode support that activates automatically:
@media (prefers-color-scheme: dark) {
.book-toc {
background: #1a1a1a;
color: #ccc;
}
}
Testing Checklist
- TOC appears on pages with headings
- Active section highlights on scroll
- Click links for smooth navigation
- Hover effects work properly
- Nested headings display correctly
- Progress bar updates on scroll
- Responsive breakpoints work
- Keyboard navigation functional
- Screen reader accessible
Troubleshooting
TOC Not Highlighting
- Check if headings have
idattributes - Verify JavaScript is loaded
- Check console for errors
Styling Not Applied
- Clear browser cache
- Verify CSS file is loaded
- Check for CSS conflicts
Smooth Scroll Not Working
- Check browser compatibility
- Verify JavaScript is enabled
- Check for conflicts with other scripts
Future Enhancements
Potential additions:
- Collapse/expand functionality
- Search within TOC
- Estimated reading time per section
- Print-friendly view
- Bookmark/favorite sections
- TOC export (PDF, Markdown)
Credits
- Design inspired by: Stripe, GitHub, and MDN documentation
- Icons: Font Awesome 6.4
- Smooth scroll: Native browser API
- Progress indicator: Custom implementation
Result: Professional, interactive Table of Contents with automatic section highlighting! 📚
