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.
| 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` || 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 |
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.
| Operator | Example | Meaning |
| :--------- | :------------------- | :------------------- |
| `\|` | `ps aux \| grep node` | Shell pipe |
| `\|\|` | `a \|\| b` | Logical OR |
| `\|>` | `x \|> f()` | Pipeline (Elixir) || Operator | Example | Meaning |
|---|---|---|
| | ps aux | grep node | Shell pipe |
|| | a || b | Logical 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.
Don't use | inside backticks: code spans show entities literally, so you get | 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:
| Syntax | Renders as |
| :------------------ | :---------------- |
| `` `code` `` | `code` |
| `` ```js `` | starts a fence || Syntax | Renders as |
|---|---|
`code` | code |
```js | starts a fence |
Every way to show code in a table
| Technique | Syntax | Works on | Notes |
|---|---|---|---|
| Inline code | npm ci | Every renderer with tables | Escape | as \| |
| One code span per line | a<br>b | Anywhere <br> works | Each line is a separate span |
HTML <code> with <br> | <code>a<br>b</code> | GitHub, GitLab, VS Code, Jupyter | Escape < as <; indent with |
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 Code | Syntax highlighting |
| Grid table | Fence inside a +---+ cell | Pandoc, Quarto | Every output format |
| Code below the table | Link from the cell to a fenced block | Everywhere | Best 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.
| Task | Commands |
| :---- | :------------------------------------------- |
| Build | `npm ci`<br>`npm run build` |
| Test | `npm test`<br>`npm run lint`<br>`npm run e2e` || Task | Commands |
|---|---|
| Build | npm cinpm run build |
| Test | npm testnpm run lintnpm 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 .
<code> and <br>| Language | Hello world |
| :------- | :---------------------------------------------------------------- |
| Python | <code>def main():<br> print("hi")</code> |
| Go | <code>func main() {<br> fmt.Println("hi")<br>}</code> || Language | Hello world |
|---|---|
| Python | def main(): |
| Go | func main() { |
Renders on GitHub, GitLab and VS Code. Markdown is still parsed between HTML tags, so escape *, _ and < (see Pitfalls).
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.
| 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:
<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.
+----------+-----------------------------+
| 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.
```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
| Platform | Inline code | Multiline (`<br>`) | Fenced code block |
|---|---|---|---|
GitHub (GFM)Escape pipes in code as \|. Fenced blocks in an HTML table cell get syntax highlighting. | Yes | Yes: <code> + <br> | Partly: HTML table, blank lines |
| GitLab (GLFM)Same rules as GitHub. | Yes | Yes: <code> + <br> | Partly: HTML table, blank lines |
ObsidianInline code works; HTML <code> renders in Reading view. | Yes | Partly: Reading view | No |
VS Code previewmarkdown-it passes code spans and inline HTML through. Escape pipes in code as \|. | Yes | Yes | Partly: HTML table, blank lines |
| JupyterMarkdown cells render inline code and sanitized HTML. | Yes | Yes | No |
| Pandoc / QuartoRaw HTML only reaches HTML output. Grid tables hold real code blocks in every format. | Yes | Partly: HTML output only | Yes: Grid tables |
Hugo (Goldmark)Inline code works; raw HTML needs markup.goldmark.renderer.unsafe = true. | Yes | Partly: Needs unsafe | Partly: HTML table + unsafe |
| RedditInline code only; no HTML. | Yes | No | No |
✅ 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
| 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
| 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
<br> is printed inside the code span| Task | Commands |
| :---- | :------------------------ |
| Build | `npm ci<br>npm run build` || Task | Commands |
|---|---|
| Build | npm ci<br>npm run build |
| Task | Commands |
| :---- | :------------------------------------------- |
| Build | `npm ci`<br>`npm run build` |
| Test | `npm test`<br>`npm run lint`<br>`npm run e2e` || Task | Commands |
|---|---|
| Build | npm cinpm run build |
| Test | npm testnpm run lintnpm run e2e |
Unescaped characters in HTML code
| 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 < and > and backslash-escape * and _:
<code>| Type | Example |
| :------ | :--------------------------------------- |
| Generic | <code>List<String> names</code> |
| Dunder | <code>\_\_init\_\_ method</code> || Type | Example |
|---|---|
| Generic | List<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 for indentation and < 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.