Tabs

Tabs organize and allow navigation between groups of content that are related and at the same level of hierarchy. Each tab should contain content that is distinct from other tabs in a set.

Content 1

Content 2

Syntax
::::{tab-set}

:::{tab-item} Label1
Content 1
:::

:::{tab-item} Label2
Content 2
:::

::::
.. tab-set::

    .. tab-item:: Label1

        Content 1

    .. tab-item:: Label2

        Content 2

See the Material Design description for further details.

Synchronised Tabs

The Selection of tab items can be synchronised across multiple tab-sets. For a tab-item to be synchronisable, add the sync option to the tab-item directive with a key unique to that set. Now when you select a tab in one set, tabs in other sets with the same key will be selected.

Note

Synchronisation requires that JavaScript is enabled.

Added in version 0.6.0: To synchronise tabs only across certain tab-sets, add the :sync-group: option to each tab-set directive with the same group name, such as :sync-group: category.

You can also add an HTML query string to the end of the page’s URL, to automatically select a tab with a specific key across all tab-sets of the group, for example:

Content 1

Content 2

Content 1

Content 2

Syntax
::::{tab-set}
:sync-group: category

:::{tab-item} Label1
:sync: key1

Content 1
:::

:::{tab-item} Label2
:sync: key2

Content 2
:::

::::

::::{tab-set}
:sync-group: category

:::{tab-item} Label1
:sync: key1

Content 1
:::

:::{tab-item} Label2
:sync: key2

Content 2
:::

::::
.. tab-set::
    :sync-group: category

    .. tab-item:: Label1
        :sync: key1

        Content 1

    .. tab-item:: Label2
        :sync: key2

        Content 2

.. tab-set::
    :sync-group: category

    .. tab-item:: Label1
        :sync: key1

        Content 1

    .. tab-item:: Label2
        :sync: key2

        Content 2

Tabbed code examples

The tab-set-code directive provides a shorthand for synced code examples. You can place any directives in a tab-set-code that produce a literal_block node with a language attribute, for example code, code-block and literalinclude. Tabs will be labelled and synchronised by the language attribute (in upper-case).

Added in version 0.6.0: You can also add an HTML query string to the end of the page’s URL, to automatically select a tab with a specific code across all tab-sets of the group, for example:

````{tab-set-code}

```{literalinclude} ./snippet.py
:language: python
```

```{code-block} javascript
a = 1;
```

````
.. tab-set-code::

    .. literalinclude:: ./snippet.py
        :language: python

    .. code-block:: javascript

        a = 1;

Tabs in other components

Tabs can be nested inside other components, such as inside dropdowns or within grid items.

Tabs in dropdown

Paragraph

Content 1

Content 2

Initial paragraph

Content 1

Content 2

Content 1

Content 2

Ending paragraph

Tab set, within tab set:

Content 1a

Content 1b

Content 2

tab-set options

sync-group

A group name for synchronised tab sets (default tab).

class

Additional CSS classes for the container element.

tab-set-code options

no-sync

Disable synchronisation of tabs.

sync-group

A group name for synchronised tab sets (default code).

class-set

Additional CSS classes for the set container element.

class-item

Additional CSS classes for the item container element.

tab-item options

selected

a flag indicating whether the tab should be selected by default.

sync

A key that is used to sync the selected tab across multiple tab-sets.

name

Set a reference-able name for the dropdown container.

class-container

Additional CSS classes for the container element.

class-label

Additional CSS classes for the label element.

class-content

Additional CSS classes for the content element.