Content Tabs¶
Content tabs allow you to organize related content into a tabbed interface, perfect for showing alternatives, platform-specific instructions, or different approaches to the same topic.
Overview¶
Content tabs provide:
- Grouped content - Organize related information
- Space efficiency - Multiple views in one location
- User choice - Let readers pick relevant content
- Synchronized tabs - Link tabs across the page
- Mobile friendly - Responsive tab interface
- Keyboard navigation - Full accessibility support
Configuration¶
Enable content tabs in mkdocs.yml
:
markdown_extensions:
- pymdownx.tabbed:
alternate_style: true # Required for Material theme
slugify: !!python/object/apply:pymdownx.slugs.slugify
kwds:
case: lower
theme:
features:
- content.tabs.link # Synchronize tab selection
Basic Usage¶
Simple Tabs¶
=== "Tab 1"
This is the content of tab 1.
It can contain any **Markdown** content.
=== "Tab 2"
This is the content of tab 2.
- Lists
- Code blocks
- Images
- Anything!
Result:
This is the content of tab 1.
It can contain any Markdown content.
This is the content of tab 2.
- Lists
- Code blocks
- Images
- Anything!
Code Examples¶
Common use case for showing code in different languages:
Advanced Features¶
Linked Tabs¶
When content.tabs.link
is enabled, tabs with the same label synchronize:
Installation Instructions:
Development Setup:
Nested Content¶
Tabs can contain any content including other tabs:
Complex Content¶
Project Overview¶
This project demonstrates a full-stack application with:
- Modern frontend framework
- RESTful API backend
- Database integration
- Authentication system
Getting Started
Follow the installation guide in the next tab
Use Cases¶
Platform-Specific Instructions¶
API Examples¶
Framework Comparisons¶
Pros: - Large ecosystem - Flexible architecture - Strong community
Cons: - Steeper learning curve - Requires additional libraries
Pros: - Gentle learning curve - Great documentation - Built-in features
Cons: - Smaller ecosystem - Less job market demand
Pros: - Full framework - TypeScript first - Enterprise ready
Cons: - Complex for small projects - Verbose syntax
Styling¶
Custom CSS¶
/* docs/assets/stylesheets/tabs.css */
/* Tab container */
.md-typeset .tabbed-set {
margin: 1em 0;
border-radius: 0.2rem;
}
/* Tab labels */
.md-typeset .tabbed-labels {
border-bottom: 2px solid var(--md-default-fg-color--lightest);
}
/* Active tab */
.md-typeset .tabbed-labels > label:checked {
color: var(--md-accent-fg-color);
border-bottom-color: var(--md-accent-fg-color);
}
/* Tab content */
.md-typeset .tabbed-content {
padding: 1em 0;
}
/* Tab hover effect */
.md-typeset .tabbed-labels > label:hover {
color: var(--md-accent-fg-color);
cursor: pointer;
}
Icon Tabs¶
Add icons to tab labels:
Python implementation
JavaScript implementation
Java implementation
Best Practices¶
1. Meaningful Labels¶
Use clear, descriptive tab labels:
2. Consistent Organization¶
Keep similar content types together:
=== "Frontend Setup"
Frontend instructions...
=== "Backend Setup"
Backend instructions...
=== "Database Setup"
Database instructions...
3. Limit Tab Count¶
Too many tabs can overwhelm:
- 2-5 tabs: Optimal
- 6-8 tabs: Maximum
- 9+ tabs: Consider restructuring
4. Mobile Considerations¶
Test on mobile devices: - Tabs scroll horizontally - Content remains readable - Touch targets are adequate
Accessibility¶
Keyboard Navigation¶
- Tab - Navigate to tab list
- Left / Right - Switch tabs
- Enter / Space - Select tab
- Screen reader announcements
ARIA Labels¶
Tabs include proper ARIA attributes:
- role="tablist"
- role="tab"
- role="tabpanel"
- aria-selected
- aria-controls
Common Patterns¶
Installation Guide¶
API Documentation¶
Integration¶
With Admonitions¶
Information
This is an informational message
Warning
This is a warning message
Danger
This is a danger message
With Code Annotations¶
Troubleshooting¶
Tabs Not Rendering¶
- Ensure
alternate_style: true
is set - Check indentation (4 spaces)
- Verify empty lines between tab markers
Linked Tabs Not Working¶
- Enable
content.tabs.link
feature - Ensure tab labels match exactly
- Check for trailing spaces
Styling Issues¶
- Clear browser cache
- Verify CSS is loaded
- Check for CSS conflicts