Skip to main content
Version: 2.0.0-beta.6 🚧


Docusaurus provides <Tabs> components that you can use thanks to MDX:

import Tabs from '@theme/Tabs';import TabItem from '@theme/TabItem';
<Tabs>  <TabItem value="apple" label="Apple" default>    This is an apple 🍎  </TabItem>  <TabItem value="orange" label="Orange">    This is an orange 🍊  </TabItem>  <TabItem value="banana" label="Banana">    This is a banana 🍌  </TabItem></Tabs>;
This is an apple 🍎

It is also possible to provide values and defaultValue props to Tabs:

<Tabs  defaultValue="apple"  values={[    {label: 'Apple', value: 'apple'},    {label: 'Orange', value: 'orange'},    {label: 'Banana', value: 'banana'},  ]}>  <TabItem value="apple">This is an apple 🍎</TabItem>  <TabItem value="orange">This is an orange 🍊</TabItem>  <TabItem value="banana">This is a banana 🍌</TabItem></Tabs>
This is an apple 🍎

Tabs props take precedence over the TabItem props:
<Tabs  defaultValue="apple"  values={[    {label: 'Apple 1', value: 'apple'},    {label: 'Orange 1', value: 'orange'},    {label: 'Banana 1', value: 'banana'},  ]}>  <TabItem value="apple" label="Apple 2">    This is an apple 🍎  </TabItem>  <TabItem value="orange" label="Orange 2">    This is an orange 🍊  </TabItem>  <TabItem value="banana" label="Banana 2" default>    This is a banana 🍌  </TabItem></Tabs>
This is an apple 🍎


By default, all tabs are rendered eagerly during the build process, and search engines can index hidden tabs.

It is possible to only render the default tab with <Tabs lazy={true} />.

Displaying a default tab#

Add default to one of the tab items to make it displayed by default. You can also set the defaultValue prop in the Tabs component to the label value of your choice.

For example, in the example above, setting default for the value="apple" tab forces it to be open by default.

If none of the children contains the default prop, neither is the defaultValue provided for the Tabs, or it refers to an non-existing value, only the tab headings appear until the user clicks on a tab.

Syncing tab choices#

You may want choices of the same kind of tabs to sync with each other. For example, you might want to provide different instructions for users on Windows vs users on macOS, and you want to changing all OS-specific instructions tabs in one click. To achieve that, you can give all related tabs the same groupId prop. Note that doing this will persist the choice in localStorage and all <Tab> instances with the same groupId will update automatically when the value of one of them is changed. Note that groupID are globally-namespaced.

<Tabs groupId="operating-systems">  <TabItem value="win" label="Windows" default>Use Ctrl + C to copy.</TabItem>  <TabItem value="mac" label="MacOS">Use Command + C to copy.</TabItem></Tabs>
<Tabs groupId="operating-systems">  <TabItem value="win" label="Windows" default>Use Ctrl + V to paste.</TabItem>  <TabItem value="mac" label="MacOS">Use Command + V to paste.</TabItem></Tabs>
Use Ctrl + C to copy.
Use Ctrl + V to paste.

For all tab groups that have the same groupId, the possible values do not need to be the same. If one tab group with chooses an value that does not exist in another tab group with the same groupId, the tab group with the missing value won't change its tab. You can see that from the following example. Try to select Linux, and the above tab groups doesn't change.

<Tabs groupId="operating-systems">  <TabItem value="win" label="Windows" default>    I am Windows.  </TabItem>  <TabItem value="mac" label="MacOS">    I am macOS.  </TabItem>  <TabItem value="linux" label="Linux">    I am Linux.  </TabItem></Tabs>
I am Windows.

Tab choices with different groupIds will not interfere with each other:

<Tabs groupId="operating-systems">  <TabItem value="win" label="Windows" default>Windows in windows.</TabItem>  <TabItem value="mac" label="MacOS">macOS is macOS.</TabItem></Tabs>
<Tabs groupId="non-mac-operating-systems">  <TabItem value="win" label="Windows" default>Windows is windows.</TabItem>  <TabItem value="unix" label="Unix">Unix is unix.</TabItem></Tabs>
Windows in windows.
Windows is windows.

Customizing tabs#

You might want to customize the appearance of certain set of tabs. To do that you can pass the string in className prop and the specified CSS class will be added to the Tabs component:

import Tabs from '@theme/Tabs';import TabItem from '@theme/TabItem';
<Tabs className="unique-tabs">  <TabItem value="Apple" default>    This is an apple 🍎  </TabItem>  <TabItem value="Orange">This is an orange 🍊</TabItem>  <TabItem value="Banana">This is a banana 🍌</TabItem></Tabs>;
This is an apple 🍎