Skip to content
All Markdown syntax

Code blocks and inline code in Markdown

Tables and code

Markdown syntax

Works everywhere
`inline code`

One backtick on each side, inside a sentence.

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

  • `inline code`
    One backtick on each side, inside a sentence.Works everywhere
  • ```js
    const x = 1;
    ```
    A fenced block. The word after the fence picks the syntax highlighting.Works everywhere
  • ~~~
    fenced with tildes
    ~~~
    Tildes work too, handy when the code contains backticks.Works everywhere
  •     indented code
    Four spaces of indent. Older form, no language.Works everywhere

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.

Related syntax