Skip to main content

sphinx-tabs

Github-CI Coverage Status PyPI

Create tabbed content in Sphinx documentation when building HTML.

For example, see the [Raw] code of docs/index.rst which generates the following:

A live demo can be found here: https://sphinx-tabs.readthedocs.io

Tabs

Installation

pip install sphinx-tabs

To enable the extension in Sphinx, add the following to your conf.py:

extensions = ['sphinx_tabs.tabs']

If needed, there is a configuration option to allow additional builders to be considered compatible. For example, to add the linkcheck builder, add the following to your conf.py:

sphinx_tabs_valid_builders = ['linkcheck']

If you are using Read The Docs for building your documentation, the extension must be added as a requirement. Please add the following to requirements.txt at the root of the project:

sphinx-tabs

Contributing

We welcome all contributions! See the EBP Contributing Guide for general details.

The simplest way to run tests is to install pre-commit for linting and tox for unit tests and documentation build:

$ pre-commit run --all
$ tox -p

Basic Tabs

Basic tabs can be coded as follows:

.. tabs::

   .. tab:: Apples

      Apples are green, or sometimes red.

   .. tab:: Pears

      Pears are green.

   .. tab:: Oranges

      Oranges are orange.

Tabs

The contents of each tab can be displayed by clicking on the tab that you wish to show. Clicking on the tab that is currently open will hide the tab's content, leaving only the tab set labels visible.

Alternatively, tab sets can be focused using :kbd:Tab. The :kbd:Left Arrow and :kbd:Right Arrow keys can then be used to navigate across the tab set and :kbd:Enter can be used to select a tab.

Grouped Tabs

Tabs can be grouped, so that changing the current tab in one tabset changes the current tab in all other tabsets containing a tab with a matching label. For example:

.. tabs::

   .. group-tab:: Linux

      Linux Line 1

   .. group-tab:: Mac OSX

      Mac OSX Line 1

   .. group-tab:: Windows

      Windows Line 1

.. tabs::

   .. group-tab:: Linux

      Linux Line 1

   .. group-tab:: Mac OSX

      Mac OSX Line 1

   .. group-tab:: Windows

      Windows Line 1

Group Tabs

If permitted by the user's browser, the last selected group tab will be remembered when changing page. As such, if any tabsets on the next page contain a tab with the same label it will be selected.

Code Tabs

Grouped tabs containing code with syntax highlighting can be created as follows:

.. tabs::

   .. code-tab:: c

         int main(const int argc, const char **argv) {
           return 0;
         }

   .. code-tab:: c++

         int main(const int argc, const char **argv) {
           return 0;
         }

   .. code-tab:: py

         def main():
             return

   .. code-tab:: java

         class Main {
             public static void main(String[] args) {
             }
         }

   .. code-tab:: julia

         function main()
         end

   .. code-tab:: fortran

         PROGRAM main
         END PROGRAM main

Code Tabs

Code tabs also support custom lexers (added via sphinx conf.py). Pass the lexers alias as the first argument of code-tab.

By default, code tabs are labelled with the language name, though a custom label can be provided as an optional second argument to the code-tabs directive:

.. tabs::

   .. code-tab:: c I love C

         int main(const int argc, const char **argv) {
           return 0;
         }

   .. code-tab:: py I love Python more

         def main():
             return

The tab label is used to group tabs, including code-tabs. As such, the same custom label should be used to group related tabs.

Release files for sphinx-tabs 3.5.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sphinx-tabs 3.5.0
File Size Uploaded
sphinx_tabs-3.5.0.tar.gz 17.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for sphinx-tabs 3.5.0
File Interpreter ABI Platform
sphinx_tabs-3.5.0-py3-none-any.whl Python 3 none any Details

Total release size: 26.9 kB

Release files / sphinx_tabs-3.5.0.tar.gz

Download URL sphinx_tabs-3.5.0.tar.gz
Size 17.0 kB
Tags Source
SHA-256 checksum
How to use checksums
91dba1187e4c35fd37380a56ac228bbd54c6c649b2351829f3bf033718277537
BLAKE2b-256 checksum
How to use checksums
ce30ca5b0de830f369968d8e3483dd45a8908fd10169c05cd9837f0bd075982e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.1

Release files / sphinx_tabs-3.5.0-py3-none-any.whl

Download URL sphinx_tabs-3.5.0-py3-none-any.whl
Size 9.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
154be49de4d5c8249ea08c5d9bf88ca8f9c31e00a178305a93cbc33e000339e5
BLAKE2b-256 checksum
How to use checksums
2e456adc5efeb19fd5fed4027e520b5c668ce58236a2b271ade5533c4c116276
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.1

Release history Release notifications | RSS feed

This release

3.5.0 This release

2 release files

3.4.7

2 release files

3.4.5

2 release files

3.4.4

2 release files

3.4.1

2 release files

3.4.0

2 release files

3.3.1

2 release files

3.3.0

2 release files

3.2.0

2 release files

3.1.0

2 release files

3.0.0

2 release files

2.1.0

2 release files

2.0.1

2 release files

2.0.0

2 release files

1.3.0

2 release files

1.2.1

2 release files

1.2.0

2 release files

1.1.13

1 release file

1.1.12

1 release file

1.1.11

1 release file

1.1.10

1 release file

1.1.9

1 release file

1.1.8

1 release file

1.1.7

1 release file

1.1.6

1 release file

1.1.5

1 release file

1.1.4

1 release file

1.1.3

1 release file

1.1.2

1 release file

1.1.1

1 release file

1.1.0

1 release file

1.0.1

1 release file

1.0.0

1 release file

0.2.2

1 release file

0.2.1

1 release file

0.2.0

1 release file

0.1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page