Code Group

Code groups display multiple code blocks as switchable tabs. Each tab is automatically labeled from the code block’s [label] metadata.

Basic usage

index.ts
import { createApp } from './app'

const app = createApp()
app.listen(3000)
app.ts
export function createApp() {
  return {
    listen(port: number) {
      console.log(`Listening on port ${port}`)
    }
  }
}
:::codegroup
  ```ts [index.ts]
  import { createApp } from './app'
  
  const app = createApp()
  app.listen(3000)
  ```
  
  ```ts [app.ts]
  export function createApp() {
    return {
      listen(port: number) {
        console.log(`Listening on port ${port}`)
      }
    }
  }
  ```
:::

Syntax

Wrap multiple fenced code blocks inside a :::codegroup directive. Use the [label] syntax on each code block to set the tab name:

:::codegroup
  ```language [Tab Label]
  code here
  ```
  
  ```language [Another Tab]
  code here
  ```
:::

The [label] in the code block meta string is used both as the tab title and as the file label displayed in the code block header.

Multi-language example

pnpm
pnpm add @explainer/ui
npm
npm install @explainer/ui
yarn
yarn add @explainer/ui