Code Blocks

Syntax-highlighted code examples

Fenced code blocks are automatically syntax-highlighted.

Basic code block

function greet(name) {
  return `Hello, ${name}!`;
}

Add a language identifier after the opening fence for syntax highlighting:

```javascript
function greet(name) {
  return `Hello, ${name}!`;
}
```

With title

Add a title after the language:

server.js
const express = require('express');
const app = express();

app.get('/', (req, res) => {
  res.send('Hello World');
});

app.listen(3000);
```javascript server.js
const express = require('express');
// ...
```

Code groups

Show the same example in multiple languages:

import requests
response = requests.get('https://api.example.com/data')
data = response.json()
<CodeGroup>
```javascript Node.js
const response = await fetch('https://api.example.com/data');
```

```python Python
response = requests.get('https://api.example.com/data')
```
</CodeGroup>