A tabbed code block component that groups multiple code blocks into a single unified view. Useful for showing the same example in different languages or alternative commands for different package managers.
In MDX, the CodeTabs component is available by default and doesn't need an explicit import.
Usage
Wrap multiple fenced code blocks with <CodeTabs> and they will render as tabs. Tab labels are
automatically inferred from the code block language.
Code
Custom Labels
Use the title meta attribute on each code block to set a custom tab label. This is especially
useful when multiple code blocks share the same language.
Code
Synced Tabs
Use the syncKey prop to keep multiple CodeTabs instances in sync. When a user selects a tab in
one group, all groups with the same syncKey update to match. The selection is persisted to
localStorage and synced across browser tabs.
Code
Programmatic Usage
Usually it's recommended to use fenced code blocks in MDX files. However, when building reusable
components (e.g. in your MDX component config), fenced code blocks aren't processed by the MDX
pipeline. Use CodeTabPanel directly instead:
Code
CodeTabPanel Props
| Prop | Type | Description |
|---|---|---|
code | string | The code content to display. Required. |
language | string | Language for syntax highlighting and label inference. |
title | string | Custom tab label. Falls back to language. |
icon | string | Override the language icon (e.g. "pnpm", "npm"). |
meta | string | Raw meta string like in code blocks (e.g. "showLineNumbers"). |
Props
| Prop | Type | Description |
|---|---|---|
syncKey | string | Sync selected tab across all CodeTabs with the same key. Persisted to localStorage and across tabs. |
hideIcon | boolean | Hide the language icon in tabs. Defaults to false. |