Skip to content

Code in Markdown Tables: Inline Code and Code Blocks

By MarkdownTables.com editorial teamUpdated

On this page

How do I put code in a table cell?

Wrap the code in single backticks, exactly as in a paragraph. Code spans are the most common content in API and CLI reference tables, and they work on every renderer that supports tables.

Inline code in every column
Markdown
| Method   | Endpoint             | Example                                   |
| :------- | :------------------- | :---------------------------------------- |
| `GET`    | `/v1/users`          | `curl https://api.example.com/v1/users`   |
| `POST`   | `/v1/users`          | `curl -X POST -d @user.json …`            |
| `DELETE` | `/v1/users/{id}`     | `curl -X DELETE …/v1/users/42`            |
Preview
MethodEndpointExample
GET/v1/userscurl https://api.example.com/v1/users
POST/v1/userscurl -X POST -d @user.json …
DELETE/v1/users/{id}curl -X DELETE …/v1/users/42

Code spans keep their contents literal: *, _ and < are shown as typed, and HTML tags inside them are printed rather than rendered. The one character that still needs attention is the pipe.

Pipes and backticks inside code

GFM splits each row into cells before it looks for code spans, so a | inside backticks still starts a new cell. Escape every pipe as \|. GitHub removes the backslash, inside code spans too.

Escaped pipes inside code spans
Markdown
| Operator   | Example              | Meaning              |
| :--------- | :------------------- | :------------------- |
| `\|`       | `ps aux \| grep node` | Shell pipe           |
| `\|\|`      | `a \|\| b`           | Logical OR           |
| `\|>`      | `x \|> f()`           | Pipeline (Elixir)    |
Preview
OperatorExampleMeaning
|ps aux | grep nodeShell pipe
||a || bLogical OR
|>x |> f()Pipeline (Elixir)

Renderers that don’t follow the GFM spec closely may leave the backslash visible inside code. There, <code>a | b</code> is a safe fallback.

Open in editor : Escaped pipes inside code spans

Don't use &#124; inside backticks: code spans show entities literally, so you get &#124; in the output. The full set of cases is on the escaping pipes page.

To show a backtick inside inline code, delimit the span with two backticks and pad it with spaces. That also works inside cells:

Backticks inside a code span
Markdown
| Syntax              | Renders as        |
| :------------------ | :---------------- |
| `` `code` ``        | `code`            |
| `` ```js ``          | starts a fence    |
Preview
SyntaxRenders as
`code`code
```jsstarts a fence

Every way to show code in a table

Code in table cells: techniques and where they work
TechniqueSyntaxWorks onNotes
Inline code npm ci Every renderer with tablesEscape | as \|
One code span per line a<br>b Anywhere <br> worksEach line is a separate span
HTML <code> with <br><code>a<br>b</code>GitHub, GitLab, VS Code, JupyterEscape < as &lt;; indent with &nbsp;
HTML <pre><pre>a<br>b</pre>GitHub and renderers that allow <pre>Block look; keeps spaces
Fenced block in HTML table<td> + blank line + ``` `GitHub, GitLab, VS CodeSyntax highlighting
Grid tableFence inside a +---+ cellPandoc, QuartoEvery output format
Code below the tableLink from the cell to a fenced blockEverywhereBest for long snippets

How do I put multiline code in a table cell?

A pipe-table row is one line of source, so a fenced block, which needs its own lines, can't start inside a cell. You have three inline options, from simplest to most faithful.

One code span per line

Close the backticks, add <br>, open them again. Best for lists of commands, where every line stands on its own.

A code span on each line
Markdown
| Task  | Commands                                     |
| :---- | :------------------------------------------- |
| Build | `npm ci`<br>`npm run build`                  |
| Test  | `npm test`<br>`npm run lint`<br>`npm run e2e` |
Preview
TaskCommands
Buildnpm ci
npm run build
Testnpm test
npm run lint
npm run e2e

The HTML code element

Unlike backticks, the HTML <code> element lets <br> through, so you get one continuous code box. Browsers collapse runs of spaces in it, so write indentation as &nbsp;.

Multiline code with <code> and <br>
Markdown
| Language | Hello world                                                       |
| :------- | :---------------------------------------------------------------- |
| Python   | <code>def main():<br>&nbsp;&nbsp;&nbsp;&nbsp;print("hi")</code>   |
| Go       | <code>func main() {<br>&nbsp;&nbsp;fmt.Println("hi")<br>}</code>  |
Preview
LanguageHello world
Pythondef main():
    print("hi")
Gofunc main() {
  fmt.Println("hi")
}

Renders on GitHub, GitLab and VS Code. Markdown is still parsed between HTML tags, so escape *, _ and < (see Pitfalls).

Open in editor : Multiline code with <code> and <br>

The HTML pre element

<pre> keeps spaces and draws the code as a block. GitHub's HTML allowlist includes it, and it can sit inline in a pipe-table cell; it still needs <br> for each line, because the row can't span several lines.

A <pre> block in a cellMarkdown
| Config | Value                                              |
| :----- | :------------------------------------------------- |
| YAML   | <pre>server:<br>  port: 8080<br>  host: 0.0.0.0</pre> |

A real code block in a cell (GitHub and GitLab)

When the code needs syntax highlighting or is more than a few lines, write the table in HTML. GitHub and GitLab parse Markdown inside a <td> when a blank line separates it from the tags, so a normal fenced block with a language tag works and is highlighted:

A fenced code block inside an HTML table cellHTML
<table>
  <tr>
    <th>Language</th>
    <th>Example</th>
  </tr>
  <tr>
    <td>Python</td>
    <td>

```python
def greet(name):
    return f"Hello, {name}"
```

</td>
  </tr>
</table>

Don't indent the fence or the closing </td> by four spaces after the blank line, or it becomes an indented code block. To start from an existing pipe table, convert it with Markdown table to HTML and edit only the code cell.

Pandoc and Quarto: code blocks in grid tables

Pandoc grid tables treat each cell as a small document, so fenced code blocks, with highlighting, work in HTML, PDF and Word output. A pipe inside a grid-table cell is plain text and needs no escaping, because the column boundaries come from the + and | borders lining up.

Code blocks in a Pandoc grid tableMarkdown
+----------+-----------------------------+
| Language | Example                     |
+==========+=============================+
| Python   | ```python                   |
|          | def greet(name):            |
|          |     return f"Hi {name}"     |
|          | ```                         |
+----------+-----------------------------+
| Shell    | ```sh                       |
|          | ls -la | grep ".md"         |
|          | ```                         |
+----------+-----------------------------+

Pandoc pipe tables follow the same one-line rule as GFM. More in the Pandoc tables guide.

Showing a table’s Markdown source as code

The other meaning of “Markdown table code block”: showing the table's source instead of rendering it, for example in documentation or an issue. Put the table in a fenced block tagged markdown (or md); GitHub highlights the pipes and leaves the text as typed.

A table shown as sourceMarkdown
```markdown
| Name | Role     |
| ---- | -------- |
| Ada  | Engineer |
```

If the snippet itself contains a triple-backtick fence, wrap it in four backticks. The Markdown table generator copies plain table source you can paste straight into the fence.

Code in tables by platform

Code in table cells by platform
PlatformInline codeMultiline (`<br>`)Fenced code block
GitHub (GFM)Escape pipes in code as \|. Fenced blocks in an HTML table cell get syntax highlighting.YesYes: <code> + <br>Partly: HTML table, blank lines
GitLab (GLFM)Same rules as GitHub.YesYes: <code> + <br>Partly: HTML table, blank lines
ObsidianInline code works; HTML <code> renders in Reading view.YesPartly: Reading viewNo
VS Code previewmarkdown-it passes code spans and inline HTML through. Escape pipes in code as \|.YesYesPartly: HTML table, blank lines
JupyterMarkdown cells render inline code and sanitized HTML.YesYesNo
Pandoc / QuartoRaw HTML only reaches HTML output. Grid tables hold real code blocks in every format.YesPartly: HTML output onlyYes: Grid tables
Hugo (Goldmark)Inline code works; raw HTML needs markup.goldmark.renderer.unsafe = true.YesPartly: Needs unsafePartly: HTML table + unsafe
RedditInline code only; no HTML.YesNoNo

✅ supported · ⚠️ partly or with a workaround · ❌ not supported · Last verified October 2026

Where the fenced block says HTML table, write the whole table in HTML and leave a blank line before and after the fence.

Common mistakes (broken vs. fixed)

An unescaped pipe in code

Broken: the cell splits at the pipeMarkdown
| Command              | Purpose     |
| -------------------- | ----------- |
| `ps aux | grep node` | Find a process |

On GitHub this row gets three cells, so grep node` moves into the next column and the backticks no longer pair up. The fix is `ps aux \| grep node`, as in the operator table above. The table validator points to rows whose cell count changed.

A fence inside a pipe cell

Broken: the row ends at the first newlineMarkdown
| Language | Example |
| -------- | ------- |
| Python   | ```python
def greet(): pass
``` |

The first line becomes a row with a stray ```python, and the rest falls out of the table. Use <code> with <br>, or the HTML table pattern.

A break inside backticks

Broken: <br> is printed inside the code span
Markdown
| Task  | Commands                  |
| :---- | :------------------------ |
| Build | `npm ci<br>npm run build` |
Preview
TaskCommands
Buildnpm ci<br>npm run build
Fixed: one span per line
Markdown
| Task  | Commands                                     |
| :---- | :------------------------------------------- |
| Build | `npm ci`<br>`npm run build`                  |
| Test  | `npm test`<br>`npm run lint`<br>`npm run e2e` |
Preview
TaskCommands
Buildnpm ci
npm run build
Testnpm test
npm run lint
npm run e2e

Unescaped characters in HTML code

Broken: <String> vanishes and __init__ turns boldMarkdown
| Type    | Example                          |
| :------ | :------------------------------- |
| Generic | <code>List<String> names</code>  |
| Dunder  | <code>__init__ method</code>     |

Inside the HTML <code> element, <String> is read as an unknown tag and dropped, and double underscores (or asterisks) become emphasis. Write &lt; and &gt; and backslash-escape * and _:

Fixed: escaped characters in <code>
Markdown
| Type    | Example                                  |
| :------ | :--------------------------------------- |
| Generic | <code>List&lt;String&gt; names</code>    |
| Dunder  | <code>\_\_init\_\_ method</code> |
Preview
TypeExample
GenericList<String> names
Dunder__init__ method

When to take the code out of the table

Tables are for comparing short values. Once a cell holds more than three or four lines of code, readers scroll sideways and lose the row. Better options:

  • Put the code under the table. Keep a name or short call in the cell and link to a heading with the full fenced block.
  • Use an HTML table with fenced blocks in cells when the side-by-side view matters, such as a “before / after” or a language comparison.
  • Collapse long snippets with <details>; see collapsible tables.
  • Use Pandoc grid tables if the document is built with Pandoc or Quarto.

Related: line breaks in cells, lists in cells, and the full Markdown table syntax reference.

Frequently asked questions

Can you put a code block in a Markdown table?

Not a fenced code block in a pipe-table cell, because a cell holds one line of inline content. Inline code in backticks works. For multiline code, use <code>line 1<br>line 2</code>, or write the table in HTML and put the fenced block in a <td> with blank lines around it.

How do I put a pipe character inside code in a table?

Escape it as \|, even inside backticks: ` a \| b `. GFM splits the row into cells before it reads code spans, so an unescaped pipe always starts a new cell. GitHub removes the backslash in the output.

How do I make a multiline code block in a GitHub table?

Use the HTML <code> element with <br> between lines: <code>line 1<br>line 2</code>. Use &nbsp; for indentation and &lt; for <. For syntax highlighting, use an HTML table with a fenced block inside the cell.

Does syntax highlighting work in a Markdown table?

Not for inline code: backtick spans and <code> elements are never highlighted. A fenced code block with a language tag inside an HTML table cell is highlighted on GitHub and GitLab, and Pandoc highlights code blocks in grid tables.

Why does <br> show up as text inside my code?

Backtick code spans are literal, so <br> inside them is printed. Close the code span before each break (` a<br>b ) or use the HTML <code> element, which does allow <br>` inside it.

How do I show a Markdown table as code without rendering it?

Wrap it in a fenced code block tagged markdown: three backticks and markdown on the line before, three backticks after. To show a code fence itself, wrap it in a fence of four backticks.

How do I put backticks inside inline code in a table?

Use a longer backtick run as the delimiter, with spaces: `` code shows code `. This works in table cells the same way as in a paragraph.