Tabbed views for Sphinx
Sphinx Tabs is a Sphinx extension that provides directives for creating tabbed content in Sphinx documentation when building HTML. It is actively maintained, with version 3.5.0 currently available, and releases frequently address compatibility with new Sphinx and Docutils versions.
Warnings
- breaking sphinx-tabs v3.5.0 (and newer versions) officially dropped support for Sphinx versions older than 7. Ensure your Sphinx installation is version 7 or higher when upgrading sphinx-tabs to 3.5.0+.
- gotcha The `.. include::` directive does not function correctly when placed inside a `.. code-tab::` directive. For including general reStructuredText content within tabs, use `.. tab::` or `.. group-tab::` instead.
- gotcha When using 'grouped tabs' by providing a group name to the `.. tabs::` directive (e.g., `.. tabs:: my-group`), ensure that the tab labels you intend to synchronize are consistent across all tab sets within that group on the same page. Inconsistent labels may lead to unexpected synchronization behavior.
- gotcha If you are building your documentation on Read The Docs, you must explicitly add `sphinx-tabs` to your `requirements.txt` file in your project's root or docs folder, in addition to installing it in your local environment, for the extension to be recognized during the build process.
- gotcha Some users have reported compatibility issues with `sphinx-tabs` and certain Sphinx themes (e.g., `pydata-sphinx-theme`), where the presence of `sphinx-tabs` can interfere with theme-specific features like version switchers, even if tabs are not actively used on the page.
Install
-
pip install sphinx-tabs
Imports
- sphinx_tabs.tabs
extensions = ['sphinx_tabs.tabs']
Quickstart
mkdir myproject
cd myproject
mkdir docs
cd docs
sphinx-quickstart # Follow prompts, say 'y' to Separate source and build dirs
# In docs/conf.py:
# extensions = [
# 'sphinx.ext.autodoc',
# 'sphinx.ext.napoleon',
# 'sphinx_tabs.tabs',
# ]
# html_theme = 'alabaster' # Or any other Sphinx theme
# In docs/index.rst:
# .. _index:
#
# Welcome to My Sphinx Tabs Project's documentation!
# ==================================================
#
# .. tabs::
#
# .. tab:: Python
#
# .. code-block:: python
#
# def hello_world():
# print("Hello, Python!")
#
# .. tab:: Shell
#
# .. code-block:: bash
#
# echo "Hello, Shell!"
#
# .. tab:: Markup
#
# Hello from **reStructuredText**!
#
# This project demonstrates `sphinx-tabs` functionality.
#
# Indices and tables
# ==================
#
# * :ref:`genindex`
# * :ref:`modindex`
# * :ref:`search`
# Then build:
# make html
# Open _build/html/index.html