Components
Tabs
Organize related content into switchable tabbed panels.
Overview
The Tabs and Tab components let you group related content under named tabs, allowing readers to switch between views without leaving the page. They are ideal for showing code in multiple languages, platform-specific instructions, or before/after comparisons.
- Tabs: The wrapper that manages the active tab state and renders the tab bar.
- Tab: An individual panel with a required
titleshown in the tab bar.
Example
bash
npm install my-packageUsage
Basic tabs
mdx
<Tabs>
<Tab title="First">Content for the first tab.</Tab>
<Tab title="Second">Content for the second tab.</Tab>
</Tabs>Code in tabs
When embedding code blocks inside tabs, add blank lines before and after each code fence:
mdx
<Tabs>
<Tab title="TypeScript">
```ts
const greet = (name: string): string => `Hello, ${name}`;
```
</Tab>
<Tab title="JavaScript">
```js
const greet = (name) => `Hello, ${name}`;
```
</Tab>
</Tabs>
Code and preview tabs
A common pattern for documentation is pairing a Code tab with an Output tab:
mdx
<Tabs>
<Tab title="Code">
```tsx
export function Hello() {
return <p>Hello world</p>;
}
```
</Tab>
<Tab title="Output">
Content rendered here.
</Tab>
</Tabs>Props
Tabs
| Prop | Type | Required | Description |
|---|---|---|---|
children | React.ReactNode | Yes | One or more Tab components to render. |
Tab
| Prop | Type | Required | Description |
|---|---|---|---|
title | string | Yes | The label shown in the tab bar for this panel. |
children | React.ReactNode | Yes | The content displayed when this tab is active. |
Notes
- The first tab is active by default.
- Tabs ignores non-element children such as whitespace and text nodes injected by MDX, so only
Tabcomponents with atitleprop are rendered. - Always add blank lines before and after code fences inside
Tabcontent to prevent MDX from collapsing them onto a single line.
Accessibility Notes
- Tab buttons are rendered as
<button>elements and are keyboard accessible. - Consider using descriptive tab titles so users can anticipate the content before switching.
- Avoid putting critical information exclusively in a non-default tab where possible.
Was this page helpful?