---
title: Code Blocks
description: Add syntax-highlighted code blocks with line numbers, filenames, and highlighting. Supports CodeGroups for multi-language examples.
---

> **For AI agents:** the complete documentation index is at [llms.txt](/docs/llms.txt). Append `.md` to any page URL for its markdown version.

Use code blocks to show commands, config files, and snippets with syntax highlighting.

## Basic Syntax Highlighting

```javascript
const greeting = "Hello, Jamdesk!";
console.log(greeting);
```

## Adding a Filename

Show the file path with the `title` attribute:

```typescript src/config.ts
export const config = {
  name: "My Docs",
  theme: "jam"
};
```

## Line Highlighting

Draw attention to specific lines with `{1,3-5}` syntax:

```javascript {1,4-6}
// This line is highlighted
const config = {
  apiKey: process.env.API_KEY,
  baseUrl: 'https://api.example.com', // highlighted
  timeout: 5000,                       // highlighted
  retries: 3,                          // highlighted
};
```

## Line Numbers

Add line numbers with `showLineNumbers`:

```python showLineNumbers
def fibonacci(n):
    if n <= 1:
        return n
    return fibonacci(n - 1) + fibonacci(n - 2)
```

## Custom Start Line

Start numbering from a specific line:

```go showLineNumbers startLine=42
func processRequest(ctx context.Context) error {
    // This is line 42
    return nil
}
```

## Combined Features

Use multiple features together:

```typescript api/client.ts showLineNumbers {3-5}
import axios from 'axios';

const client = axios.create({
  baseURL: process.env.API_URL,
  timeout: 10000,
});

export default client;
```

## Code Groups

Show the same code in multiple languages:

<CodeGroup>
```bash cURL
curl -X POST https://api.example.com/posts \
  -H "Authorization: Bearer $API_KEY"
```

```javascript JavaScript
const response = await fetch('https://api.example.com/posts', {
  method: 'POST',
  headers: { 'Authorization': `Bearer ${API_KEY}` }
});
```

```python Python
import requests
response = requests.post(
    'https://api.example.com/posts',
    headers={'Authorization': f'Bearer {API_KEY}'}
)
```
</CodeGroup>

## Available Themes

Configure syntax highlighting themes in `docs.json`:

```json docs.json
{
  "styling": {
    "codeblocks": {
      "theme": {
        "light": "github-light",
        "dark": "github-dark"
      }
    }
  }
}
```

<Accordion title="View supported themes">

Popular themes include:

- **GitHub**: `github-dark`, `github-light`, `github-dark-default`, `github-light-default`
- **Dark themes**: `tokyo-night`, `one-dark-pro`, `dracula`, `nord`, `vitesse-dark`
- **Light themes**: `vitesse-light`, `min-light`
- **Catppuccin**: `catppuccin-mocha`, `catppuccin-latte`

</Accordion>

## CSS Variables Theme

For complete control over syntax highlighting colors, use the CSS Variables theme:

```json docs.json
{
  "styling": {
    "codeblocks": {
      "theme": "css-variables"
    }
  }
}
```

Then customize colors in your `style.css`:

```css style.css
:root {
  --jd-token-keyword: #ff7b72;
  --jd-token-string: #a5d6ff;
  --jd-token-comment: #8b949e;
  --jd-token-function: #d2a8ff;
  --jd-token-constant: #79c0ff;
  --jd-token-parameter: #ffa657;
}
```

<Accordion title="View all CSS variables">

| Variable | Description |
| -------- | ----------- |
| `--jd-color-text` | Default text color |
| `--jd-color-background` | Code block background |
| `--jd-token-keyword` | Keywords (if, const, function) |
| `--jd-token-string` | String literals |
| `--jd-token-comment` | Comments |
| `--jd-token-function` | Function names |
| `--jd-token-constant` | Constants |
| `--jd-token-parameter` | Function parameters |
| `--jd-token-punctuation` | Brackets, commas |
| `--jd-token-link` | URLs and links |

</Accordion>

## What's Next?

<Columns cols={2}>
  <Card title="SEO Optimization" icon="magnifying-glass-chart" href="/content/seo">
    Improve discovery and metadata
  </Card>
  <Card title="Frontmatter" icon="file-lines" href="/content/frontmatter">
    Define titles, descriptions, and SEO fields
  </Card>
</Columns>
