Sphinx extension for creating tabbed views in HTML documentation with syntax highlighting and synchronization.
npx @tessl/cli install tessl/pypi-sphinx-tabs@3.4.0A Sphinx extension that enables developers to create tabbed content in HTML documentation. Sphinx Tabs provides multiple tab types including basic tabs, synchronized group tabs, and code tabs with syntax highlighting. The extension supports keyboard navigation, remembers tab selections across pages, and provides configuration options for various Sphinx builders.
pip install sphinx-tabsAdd the extension to your Sphinx configuration:
# conf.py
extensions = ['sphinx_tabs.tabs']# conf.py - Basic setup
extensions = ['sphinx_tabs.tabs']
# Optional configuration
sphinx_tabs_valid_builders = ['linkcheck'] # Additional compatible builders
sphinx_tabs_disable_css_loading = False # Use custom CSS
sphinx_tabs_disable_tab_closing = False # Disable tab closingBasic tabs in reStructuredText:
.. tabs::
.. tab:: Python
Python code example:
.. code-block:: python
def hello():
print("Hello from Python!")
.. tab:: JavaScript
JavaScript code example:
.. code-block:: javascript
function hello() {
console.log("Hello from JavaScript!");
}Sphinx Tabs uses a hierarchical structure of custom docutils nodes that render to accessible HTML:
SphinxTabsContainer wraps entire tab setsSphinxTabsTablist contains clickable SphinxTabsTab buttonsSphinxTabsPanel contains the tab contenttabs, tab, group-tab, code-tab) generate the node structureThe extension integrates with Sphinx's builder system and supports various output formats while maintaining ARIA accessibility standards.
Core RST directives for creating different types of tabbed content including basic tabs, synchronized group tabs, and syntax-highlighted code tabs.
# Directive registration in setup()
app.add_directive("tabs", TabsDirective)
app.add_directive("tab", TabDirective)
app.add_directive("group-tab", GroupTabDirective)
app.add_directive("code-tab", CodeTabDirective)Sphinx configuration values for customizing tab behavior, compatible builders, and asset loading.
# Configuration values
sphinx_tabs_valid_builders = [] # List of additional compatible builders
sphinx_tabs_disable_css_loading = False # Boolean to disable CSS loading
sphinx_tabs_disable_tab_closing = False # Boolean to disable tab closingMain extension setup function and compatibility detection for different Sphinx builders.
def setup(app):
"""Set up the sphinx-tabs extension"""
# Returns: dict with parallel processing settings
def get_compatible_builders(app):
"""Get list of builders compatible with sphinx-tabs"""
# Returns: list of builder names