APIToGoAPIToGo
Visit APIToGo on LinkedIn
  • Documentation
  • Components
  • Themes
General
Documentation
    CodeTabsMermaidAPI PlaygroundSecretStepperSyntax Highlight
Form
Utility
powered by apitogo
Documentation

CodeTabs

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.

MDXCode
<CodeTabs> ```ts const greeting: string = "Hello, world!"; console.log(greeting); ``` ```js const greeting = "Hello, world!"; console.log(greeting); ``` ```py greeting = "Hello, world!" print(greeting) ``` </CodeTabs>

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.

MDXCode
<CodeTabs> ```sh title="pnpm" icon="pnpm" pnpm add @lukoweb/apitogo ``` ```sh title="npm" icon="npm" npm install @lukoweb/apitogo ``` ```sh title="yarn" icon="yarn" yarn add @lukoweb/apitogo ``` </CodeTabs>

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.

MDXCode
<CodeTabs syncKey="package-manager"> ```sh title="pnpm" icon="pnpm" pnpm add @lukoweb/apitogo ``` ```sh title="npm" icon="npm" npm install @lukoweb/apitogo ``` </CodeTabs> <!-- repeat above -->

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
import { CodeTabs, CodeTabPanel } from "@lukoweb/apitogo/ui/CodeTabs"; const InstallTabs = ({ pkg }: { pkg: string }) => ( <CodeTabs syncKey="package-manager"> <CodeTabPanel language="sh" title="pnpm" icon="pnpm" code={`pnpm add ${pkg}`} /> <CodeTabPanel language="sh" title="npm" icon="npm" code={`npm install ${pkg}`} /> <CodeTabPanel language="sh" title="yarn" icon="yarn" code={`yarn add ${pkg}`} /> </CodeTabs> );

CodeTabPanel Props

PropTypeDescription
codestringThe code content to display. Required.
languagestringLanguage for syntax highlighting and label inference.
titlestringCustom tab label. Falls back to language.
iconstringOverride the language icon (e.g. "pnpm", "npm").
metastringRaw meta string like in code blocks (e.g. "showLineNumbers").

Props

PropTypeDescription
syncKeystringSync selected tab across all CodeTabs with the same key. Persisted to localStorage and across tabs.
hideIconbooleanHide the language icon in tabs. Defaults to false.
Last modified on March 31, 2026
TypographyMermaid
On this page
  • Usage
  • Custom Labels
  • Synced Tabs
  • Programmatic Usage
    • CodeTabPanel Props
  • Props
const greeting: string = "Hello, world!"; console.log(greeting);
pnpm add @lukoweb/apitogo
pnpm run build
pnpm run build
React