Use single backticks for code inside a sentence and a fence of three backticks for a block. Add a language name after the opening fence (js, python, bash, json, diff) to get syntax highlighting.
All ways to write it
One backtick on each side, inside a sentence.Works everywhere`inline code`
A fenced block. The word after the fence picks the syntax highlighting.Works everywhere```js const x = 1; ```
Tildes work too, handy when the code contains backticks.Works everywhere~~~ fenced with tildes ~~~
Four spaces of indent. Older form, no language.Works everywhereindented code
Example
You type
Run `npm run build` first, then:
```bash
curl -X POST https://example.com/api/import \
-H "Authorization: Bearer $TOKEN"
```You get
Run npm run build first, then:
curl -X POST https://example.com/api/import \
-H "Authorization: Bearer $TOKEN"
Questions
How do I show backticks inside inline code?
Wrap it in two backticks with spaces: `` `code` `` shows `code` with its backticks.
How do I show a code fence inside a code block?
Use a longer outer fence: four backticks around a block that contains three, or tildes around backticks.
Which language names work?
Highlighters use their own lists; js, ts, python, java, bash, json, yaml, sql, html, css and diff are safe nearly everywhere.
Code block in Confluence
Markdown Macro+ highlights fenced code blocks by language, and Markdown Importer turns them into Confluence code blocks with highlighting. For Confluence's own code formatting, see inline code and code blocks in Confluence.