mirror of
https://github.com/mintlify/docs.git
synced 2026-09-14 13:35:46 +08:00
d6960c72bf
* Improve SEO metadata: fix titles, descriptions, and remove redundant OpenAPI descriptions - Remove description frontmatter from 19 API pages where the OpenAPI spec already supplies the description - Fix 2 titles that exceeded 60 characters (content-templates, content-types) - Improve 15 descriptions that were too short (<130 chars) or too long (>160 chars) to target 130-155 characters - All descriptions are unique and include relevant search terms Generated-By: mintlify-agent * re-add API descriptions * Apply suggestion from @ethanpalm * Apply suggestion from @ethanpalm * Apply suggestion from @ethanpalm * Apply suggestion from @ethanpalm --------- Co-authored-by: mintlify[bot] <109931778+mintlify[bot]@users.noreply.github.com> Co-authored-by: Ethan Palm <56270045+ethanpalm@users.noreply.github.com>
103 lines
2.4 KiB
Plaintext
103 lines
2.4 KiB
Plaintext
---
|
|
title: "Code groups"
|
|
description: "Use the CodeGroup component to display multiple code examples in a tabbed interface and let readers compare implementations across languages."
|
|
keywords: ["code groups", "tabbed code", "multi-language examples", "CodeGroup"]
|
|
---
|
|
|
|
Use the `CodeGroup` component to display multiple code blocks in a tabbed interface, allowing users to compare implementations across different programming languages or see alternative approaches for the same task.
|
|
|
|
<CodeGroup>
|
|
|
|
```javascript helloWorld.js
|
|
console.log("Hello World");
|
|
```
|
|
|
|
```python hello_world.py
|
|
print('Hello World!')
|
|
```
|
|
|
|
```java HelloWorld.java
|
|
class HelloWorld {
|
|
public static void main(String[] args) {
|
|
System.out.println("Hello, World!");
|
|
}
|
|
}
|
|
```
|
|
|
|
</CodeGroup>
|
|
|
|
Code groups inherit global styling from your `docs.json` file. Customize your theme using `styling.codeblocks`. See [Settings](/organize/settings-appearance#styling) for configuration options.
|
|
|
|
Code groups automatically synchronize with other code groups and [tabs](/components/tabs) on the same page when their labels match. When you select a language in one code group, all tabs and code groups with matching labels update to show the same language.
|
|
|
|
## Create code groups
|
|
|
|
To create a code group, wrap multiple code blocks with `<CodeGroup>` tags. Each code block must include a title, which becomes the tab label.
|
|
|
|
````mdx
|
|
<CodeGroup>
|
|
|
|
```javascript helloWorld.js
|
|
console.log("Hello World");
|
|
```
|
|
|
|
```python hello_world.py
|
|
print('Hello World!')
|
|
```
|
|
|
|
```java HelloWorld.java
|
|
class HelloWorld {
|
|
public static void main(String[] args) {
|
|
System.out.println("Hello, World!");
|
|
}
|
|
}
|
|
```
|
|
|
|
</CodeGroup>
|
|
````
|
|
|
|
## Language dropdown
|
|
|
|
You can replace the tabs in a code group with a dropdown menu to toggle between languages using the `dropdown` prop.
|
|
|
|
<CodeGroup dropdown>
|
|
|
|
```javascript helloWorld.js
|
|
console.log("Hello World");
|
|
```
|
|
|
|
```python hello_world.py
|
|
print('Hello World!')
|
|
```
|
|
|
|
```java HelloWorld.java
|
|
class HelloWorld {
|
|
public static void main(String[] args) {
|
|
System.out.println("Hello, World!");
|
|
}
|
|
}
|
|
```
|
|
|
|
</CodeGroup>
|
|
|
|
````mdx highlight=1
|
|
<CodeGroup dropdown>
|
|
|
|
```javascript helloWorld.js
|
|
console.log("Hello World");
|
|
```
|
|
|
|
```python hello_world.py
|
|
print('Hello World!')
|
|
```
|
|
|
|
```java HelloWorld.java
|
|
class HelloWorld {
|
|
public static void main(String[] args) {
|
|
System.out.println("Hello, World!");
|
|
}
|
|
}
|
|
```
|
|
</CodeGroup>
|
|
````
|