Skip to content

Code groups

Show the same code in several languages or package managers, as tabs or a dropdown.

Updated

A CodeGroup turns the code blocks inside it into tabs. A block’s tab is named by its title, or its language when it has none. For block titles and other options, see formatting.

npm
npm install specly
MDX
<CodeGroup>
```bash npm
npm install specly
```
```bash pnpm
pnpm add specly
```
```bash yarn
yarn add specly
```
</CodeGroup>

Leave a blank line between the tag and the code blocks.

When a reader picks a tab, every group on the site that has that language (or that package manager) switches with it, and Specly remembers the choice for their next visit.

Node
console.log('hello');
MDX
<CodeGroup dropdown>
```js Node
console.log('hello');
```
```python Python
print('hello')
```
</CodeGroup>
dropdownbooleandefault: false

Shows a select box in place of the tabs.

syncbooleandefault: true

Set sync={false} to keep a group to itself, so it neither follows nor changes the reader’s choice.

Was this page helpful?

Report a problem

What’s the problem?

The docs team sees this. Other readers don’t.