> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.manicule.dev/zh/llms.txt
> Use this file to discover all available pages before exploring further.
> For every page in one file, fetch https://mintlify.manicule.dev/zh/llms-full.txt (large).
> To search and read these docs as tools, connect the MCP server at https://mintlify.manicule.dev/api/mcp.
> Every agent surface: https://mintlify.manicule.dev/.well-known/llms-manifest.json

# 代码分组 (/zh/components/code-groups)

<!-- agent-signals: reading_time_min: 1 · est_tokens: 450 · updated: 2026-07-31 -->
Related: [折叠面板](/zh/components/accordions.md), [徽章](/zh/components/badge.md), [横幅](/zh/components/banner.md), [标注框](/zh/components/callouts.md), [卡片](/zh/components/cards.md), [颜色](/zh/components/color.md)

> 使用 CodeGroup 组件在标签页界面中展示多个代码示例，让读者可以比较不同编程语言的实现方式。

使用 `CodeGroup` 组件在带有标签页的界面中展示多个代码块，便于用户比较不同编程语言的实现，或查看完成同一任务的替代方案。

<CodeGroup>
```javascript title="helloWorld.js"
console.log("Hello World");
```

```python title="hello_world.py"
print('Hello World!')
```

```java title="HelloWorld.java"
class HelloWorld {
    public static void main(String[] args) {
        System.out.println("Hello, World!");
    }
}
```
</CodeGroup>

代码分组将从你的 `docs.json` 文件继承全局样式。可通过 `styling.codeblocks` 自定义主题。配置选项参见 [Settings](/zh/organize/settings-appearance#styling)。

当标签相同时，同一页面上的代码分组会与其他代码分组以及 [Tabs](/zh/components/tabs) 自动同步。当你在某个代码分组中选择一种语言时，所有具有相同标签的 Tabs 和代码分组都会更新为显示相同的语言。

<div id="creating-code-groups">
  ## 创建代码组
</div>

要创建代码组，请使用 `<CodeGroup>` 标签包裹多个代码块。每个代码块必须包含一个 title，其值将作为标签页的标签。

````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("你好，世界！");
    }
}
```

</CodeGroup>
````

<div id="language-dropdown">
  ## 语言下拉菜单
</div>

你可以通过使用 `dropdown` 属性，将 CodeGroup 中的选项卡替换为下拉菜单，以在不同语言之间切换。

<CodeGroup dropdown>
```javascript title="helloWorld.js"
console.log("Hello World");
```

```python title="hello_world.py"
print('Hello World!')
```

```java title="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("你好世界");
```

```python hello_world.py
print('你好世界!')
```

```java HelloWorld.java
class HelloWorld {
    public static void main(String[] args) {
        System.out.println("你好，世界！");
    }
}
```
</CodeGroup>
````
