--- id: tabs title: Tabs description: Using tabs inside Docusaurus Markdown slug: /markdown-features/tabs --- ```mdx-code-block import BrowserWindow from '@site/src/components/BrowserWindow'; import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; ``` Docusaurus provides `` components that you can use thanks to [MDX](./markdown-features-react.mdx): ```jsx import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; This is an apple 🍎 This is an orange 🍊 This is a banana 🍌 ``` ```mdx-code-block This is an apple 🍎 This is an orange 🍊 This is a banana 🍌 ``` --- It is also possible to provide `values` and `defaultValue` props to `Tabs`: ```jsx This is an apple 🍎 This is an orange 🍊 This is a banana 🍌 ``` ```mdx-code-block This is an apple 🍎 This is an orange 🍊 This is a banana 🍌
```
Tabs props take precedence over the TabItem props: ```jsx This is an apple 🍎 This is an orange 🍊 This is a banana 🍌 ``` ```mdx-code-block This is an apple 🍎 This is an orange 🍊 This is a banana 🍌
```
:::tip 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 ``. ::: ## 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 {#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 `` instances with the same `groupId` will update automatically when the value of one of them is changed. Note that `groupID` are globally-namespaced. ```jsx // highlight-next-line Use Ctrl + C to copy. Use Command + C to copy. // highlight-next-line Use Ctrl + V to paste. Use Command + V to paste. ``` ```mdx-code-block Use Ctrl + C to copy. Use Command + C to copy. Use Ctrl + V to paste. Use Command + 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. ```jsx I am Windows. I am macOS. I am Linux. ``` ```mdx-code-block I am Windows. I am macOS. I am Linux. ``` --- Tab choices with different `groupId`s will not interfere with each other: ```jsx // highlight-next-line Windows in windows. macOS is macOS. // highlight-next-line Windows is windows. Unix is unix. ``` ```mdx-code-block Windows in windows. macOS is macOS. Windows is windows. Unix is unix. ``` ## Customizing tabs {#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: ```jsx import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; // highlight-next-line This is an apple 🍎 This is an orange 🍊 This is a banana 🍌 ; ``` ```mdx-code-block This is an apple 🍎 This is an orange 🍊 This is a banana 🍌 ```