/Docs
Search docs or ask a question⌘K
DocsAgent
Changelog
Components Code Blocks

Code Blocks

Syntax highlighting, code groups, line numbers, and more.

4 min read

Syntext provides powerful code block features including syntax highlighting for 50+ languages, tabbed code groups, line highlighting, and more.

Basic Code Block

Use fenced code blocks with a language identifier:

mdx
```typescript
const greeting = "Hello, World!";
console.log(greeting);
```

Renders with syntax highlighting:

typescript
const greeting = "Hello, World!";
console.log(greeting);

Supported Languages

Common languages: javascript, typescript, python, go, rust, java, ruby, php, bash, shell, json, yaml, sql, graphql, html, css, markdown.

See the full list of supported languages.

Code Block Title

Add context with a title:

mdx
```typescript title="src/index.ts"
export function greet(name: string): string {
return `Hello, ${name}!`;
}
```
src/index.ts
export function greet(name: string): string {
return `Hello, ${name}!`;
}

Every code block gets a header automatically: the title (or a pretty language name like "TypeScript" — shell languages show as "Terminal") appears on the left, with a language chip and copy button on the right. When you provide a title, the language chip keeps the language visible.

On doc engine v2 the header shows the title, or the fence's language. Fences tagged console, terminal or shell-session render as a terminal window instead, with $ lines drawn as prompts.

This applies on guide pages and API reference pages alike. Inside a <CodeGroup> the tab bar is the header, so the copy and Ask-AI buttons move into it, on the right, and follow the selected tab.

Line Numbers

Show line numbers with showLineNumbers:

mdx
```typescript showLineNumbers
const a = 1;
const b = 2;
const sum = a + b;
console.log(sum);
```
typescript
1const a = 1;
2const b = 2;
3const sum = a + b;
4console.log(sum);

The numbers are drawn by CSS rather than inserted into the block, so Copy still copies the code alone — no numbers come along with it. On doc engine v1 a single-line fence gets no gutter, because it reads as a command rather than a listing; v2 numbers every line of a fence that asks for it.

To number every source block on the site instead of asking per fence, set features.codeLineNumbers (doc engine v1 only — on v2, use showLineNumbers per fence). The two combine: the site flag sets the default and showLineNumbers turns the gutter on for one block regardless. Request and response panels on API reference pages are never numbered — a payload is not a listing.

Line Highlighting

Highlight specific lines:

mdx
```typescript {2,4-5}
function process(data: Data) {
const validated = validate(data); // highlighted
const result = transform(validated); // highlighted
return result; // highlighted
}
```
typescript
function process(data: Data) {
const validated = validate(data);
const result = transform(validated);
return result;
}

Both spellings work: the bare {2,4-5} above, and an explicit highlight={2,4-5} where a bare brace would read ambiguously next to other meta. A range is inclusive, a list may mix ranges and single lines, and a malformed spec highlights nothing rather than failing the build. Highlighting combines with showLineNumbers, and theme={null} still opts the fence out of highlighting entirely.

CodeGroup (Tabbed Code)

Show multiple code variants in tabs:

mdx
<CodeGroup>
```bash title="curl"
curl https://api.example.com/users
```
```typescript title="TypeScript"
const users = await client.users.list();
```
```python title="Python"
users = client.users.list()
```
</CodeGroup>
curlTypeScriptPython
curl https://api.example.com/users

Each fenced code block directly inside <CodeGroup> becomes a tab. The tab is labelled by the fence's title="...", or by its language when there is no title. A bare word after the language, as in ```bash cURL, is not a label: it is ignored and the tab shows bash.

Note

On doc engine v1, the reader's language choice is saved and applied across all CodeGroups on the site. On doc engine v2, a language picked in an API page's request panel is remembered and switches CodeGroup tabs with the same label on every page; a click on a CodeGroup tab switches only that block.

Diff Highlighting

Show code changes with diff language:

mdx
```diff
- const old = "before";
+ const new = "after";
```
diff
- const old = "before";
+ const new = "after";

Terminal Output

Use bash or shell for terminal commands:

mdx
```bash
npm install @syntext/sdk
```
bash
npm install @syntext/sdk

For output without a prompt:

mdx
```text
Build complete in 2.3s
Output: ./dist (4.2 MB)
```
text
Build complete in 2.3s
Output: ./dist (4.2 MB)

JSON with Comments

jsonc
{
// Configuration file
"name": "my-docs",
"version": "1.0.0"
}

Inline Code

Use backticks for inline code:

mdx
Use the `--force` flag to overwrite existing files.

Use the --force flag to overwrite existing files.

Disabling Highlighting

Add theme={null} (or theme="none") to the fence meta to skip syntax highlighting entirely — useful for log output, ASCII diagrams, or intentionally plain snippets:

mdx
```text theme={null}
2026-06-22 14:03:11 INFO build started
2026-06-22 14:03:42 INFO build finished in 31s
```

The block keeps its copy button and header but renders without token colors.

Code Block Props

PropExampleDescription
Language ```typescriptSyntax highlighting
titletitle="app.ts"File name or description
showLineNumbersshowLineNumbersDisplay line numbers
{lines}{2,4-6}Highlight specific lines
highlighthighlight={2,4-6}Explicit spelling of the same thing
themetheme={null}Disable syntax highlighting for this block

Best Practices

Tip

Always specify a language for syntax highlighting. Use text or plaintext for raw output.

•
Use title for file paths to provide context
•
Group related code samples with <CodeGroup>
•
Keep code examples focused and minimal
•
Test that all code examples actually work
Was this page helpful? Yes No
Previous
Next
Product
Resources
Company
© 2026 SyntextBuilt with Syntext