Code Groups

Code Groups let you show multiple related code files together, perfect for showing different files in a project or different versions of the same code.

Basic Code Group

dart
void main() {
runApp(MyApp());
}
markdown
<CodeGroup>
  <Code title="main.dart" language="dart">
void main() {
  runApp(MyApp());
}
  </Code>
  <Code title="pubspec.yaml" language="yaml">
name: my_app
dependencies:
  flutter:
    sdk: flutter
  </Code>
</CodeGroup>

Project Structure Example

Show how files work together:

dart
import 'package:flutter/material.dart';
import 'app.dart';

void main() {
runApp(const MyApp());
}

Configuration Files

yaml
name: My Docs
description: Documentation for My Project

nav:
- label: Docs
  href: /

sidebar:
- group: Getting Started
  pages:
    - index
    - installation

API Request/Response

bash
curl -X POST https://api.example.com/users \
-H "Content-Type: application/json" \
-d '{"name": "John", "email": "john@example.com"}'

Before/After Example

dart
// Old approach - manual state management
class Counter {
int _value = 0;

void increment() {
  _value++;
  notifyListeners();
}
}

Supported Languages

Code Groups support all the same languages as regular code blocks:

  • dart, javascript, typescript, python, go, rust
  • java, kotlin, swift, c, cpp, csharp
  • ruby, php, sql, graphql
  • yaml, json, toml, xml
  • bash, shell, powershell
  • html, css, scss
  • And many more...

Code Groups vs Tabs

Info

Use Code Groups when showing related files that work together.

Use Tabs when showing alternative implementations (different languages doing the same thing).

Code Groups - Multiple files in one project:

html
<div id="app"></div>

Tabs - Same thing in different languages:

javascript
console.log('Hello');