Code Blocks
Syntax highlighting, code groups, line numbers, and more.
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:
Renders with syntax highlighting:
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:
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:
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:
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:
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.
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:
Terminal Output
Use bash or shell for terminal commands:
For output without a prompt:
JSON with Comments
Inline Code
Use backticks for inline code:
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:
The block keeps its copy button and header but renders without token colors.
Code Block Props
| Prop | Example | Description |
|---|---|---|
| Language | ```typescript | Syntax highlighting |
title | title="app.ts" | File name or description |
showLineNumbers | showLineNumbers | Display line numbers |
{lines} | {2,4-6} | Highlight specific lines |
highlight | highlight={2,4-6} | Explicit spelling of the same thing |
theme | theme={null} | Disable syntax highlighting for this block |
Best Practices
Always specify a language for syntax highlighting. Use text or plaintext for raw output.
title for file paths to provide context<CodeGroup>