Blog

Markdown Tables: Syntax, Alignment and Examples

Learn Markdown table syntax: pipes, header rows, alignment, escaped pipes and code in cells. Copy a working example and avoid the errors that break tables.

By Markdown Viewer5 min read

A Markdown table is three lines of setup and then one line per row. It is also the part of Markdown people get wrong most often, because a single missing pipe silently turns a table into a paragraph of text.

This is the complete syntax, the alignment rules, and the fixes for the errors that actually show up in READMEs and docs.

The basic table

| Language | Extension | Renders in browser |
| :------- | :-------- | :----------------- |
| Markdown | .md       | Yes                |
| HTML     | .html     | Yes                |

It renders as:

Language Extension Renders in browser
Markdown .md Yes
HTML .html Yes

Three parts are mandatory:

  1. The header row — the column titles.
  2. The delimiter row — dashes under each header, which is how the parser knows this is a table rather than text with pipes.
  3. At least one body row. A header plus delimiter with no rows renders as nothing in many parsers.

Alignment

Colons in the delimiter row set each column’s alignment:

| Left   | Center | Right  |
| :----- | :----: | -----: |
| text   | text   | 1,240  |
| more   | more   | 87     |
Left Center Right
text text 1,240
more more 87
  • :--- left
  • :---: center
  • ---: right
  • --- defaults to left in most renderers (GitHub included)

Alignment is presentation only. It does not change the data, and a viewer that ignores it is still correct Markdown.

Writing a table without counting spaces

The source does not need to be padded. These two tables are identical to a parser:

|a|b|
|-|-|
|1|2|
| a | b |
| --- | --- |
| 1 | 2 |

Padding makes the raw file readable in a text editor; it changes nothing in the output. Most editors have a “format table” command, and the Markdown table generator builds a padded table from a visual grid if you would rather not type pipes at all.

Special characters inside cells

Pipe characters

A | inside a cell splits the cell. Escape it with a backslash:

| Operator | Meaning          |
| :------- | :--------------- |
| `a \| b` | bitwise OR       |

Alternatively, use the HTML entity |, which survives some parsers that mishandle the backslash.

Inline code

Backticks work in cells, but code that contains a pipe still needs the pipe escaped:

| Command        | Effect                  |
| :------------- | :---------------------- |
| `ls -la`       | list all files          |
| `grep -E "a\|b"` | match a or b          |

Line breaks

Standard Markdown tables cannot contain a blank line or a multi-line paragraph in a cell. Two workarounds:

  • <br> inside the cell, which GitHub and most HTML-enabled renderers honour.
  • Split the content into two rows or move long prose out of the table.

Lists inside cells are not portable. If a cell needs a list, the table is probably the wrong format.

What Markdown tables cannot do

Worth knowing before you fight the syntax:

Want Supported in standard Markdown Workaround
Column widths No Renderer decides; CSS can override
Rowspan / colspan No HTML <table>
Captions No A paragraph above the table, or <caption> in HTML
Footnotes in cells Parser-dependent Put the note after the table
Nested tables No Split the table

If you genuinely need merged cells, write raw HTML. Markdown allows it, but the file stops being portable to renderers that strip HTML.

Tables in GitHub, GitLab and CommonMark

Pipe tables are not part of the original Markdown specification — they come from GitHub Flavored Markdown (GFM), which is what GitHub, GitLab, Reddit and most modern renderers implement. Text surrounded by pipes in a strict CommonMark renderer may appear as literal text.

In practice: if your document will be read on GitHub or in a modern editor, pipe tables are safe. If it targets a very old or strict converter, check the output before shipping.

GitHub has one extra rule worth remembering: a row with a different number of cells than the header is not rejected, it is padded or truncated. The table still renders, with content quietly missing, so count your cells.

Tables copied from Excel, Word or CSV

Pasting a spreadsheet into Markdown does not produce a table — it produces tab-separated text. Two clean routes:

  1. Convert the data. A CSV-to-Markdown step adds the header and delimiter rows and pads the columns.
  2. Build the table from the grid. The table generator accepts pasted tab-separated data and emits a valid Markdown table, which you then paste back into your document.

Either way, check the alignment row afterwards: it is the one line a converter is most likely to omit.

Previewing the result

Tables are the easiest thing to get subtly wrong, so preview while you write. The Markdown viewer renders tables live as you type, and the reader does the same without editor chrome if you are checking a file someone sent you.

If a table renders as one long line of text with pipes, the cause is almost always one of these:

  • the delimiter row is missing;
  • the delimiter row has a different number of columns than the header;
  • a cell contains an unescaped |;
  • there is no blank line before the table, so it is being read as part of the previous paragraph.

Frequently asked questions

Do I need a pipe at the start and end of each row?

No. Language | Extension is valid. Leading and trailing pipes make the raw file easier to read and are what GitHub’s own docs use, so most people keep them.

How many dashes are required in the delimiter row?

At least one per column (|-|-|) is valid; three is the common style. Alignment colons count as part of the delimiter.

Can a Markdown table have no header?

No — the header row plus delimiter is the syntax that identifies a table. To hide the header visually, use HTML or a CSS rule in your renderer.

Why does my table only show one column?

Your delimiter row probably has one column, so every extra pipe is being ignored as padding. Make the number of delimiter columns match the header exactly.

Try it in the browser

Open a .md file, edit it with live preview, and export to PDF, HTML or DOCX — all on your device, with no sign-up and no upload.

Open the Markdown viewer