To write a Markdown table, type a header row, a delimiter row of hyphens, then one line per data row, with pipes (|) between cells.[1] That is the whole structure: a single header row, a delimiter row separating the header from the data, and zero or more data rows.[1] Add colons to the hyphens to set column alignment. Tables are not part of core CommonMark, so this syntax comes from the GitHub Flavored Markdown (GFM) extension.[3] This guide shows the exact syntax, the rendered HTML from the spec, a reference table for alignment and failure cases, and the mistakes that stop a table from rendering. To check a table as you type, paste it into the free Markdown editor.
The minimal Markdown table
Here is the smallest useful table, taken from the GFM spec (Example 198).[1]
| foo | bar |
| --- | --- |
| baz | bim |
The first line is the header row. The second line is the delimiter row: its cells contain only hyphens, and optionally colons.[1] Everything after that is a data row. The spec gives this HTML for it:
| foo | bar |
| --- | --- |
| baz | bim |
Two things follow from that output. The header row becomes <thead> with <th> cells, so you never write the header markup yourself. And the delimiter row produces no output at all. It exists only to tell the parser that the line above it is a header.
The four rules that define a table
The spec packs the syntax into a short passage. Each sentence maps to a habit worth building.
Pipes separate cells. Each row consists of cells containing arbitrary text, separated by pipes, and inline Markdown is parsed inside them.[1] Bold, links and inline code all work in a cell.
Outer pipes are recommended, not required. The spec recommends a leading and trailing pipe for clarity of reading, and for when there is otherwise parsing ambiguity.[1] GitHub's documentation agrees that the pipes on either end of the table are optional.[2] Write them anyway, since the spec recommends them for clarity and to avoid parsing ambiguity.
Spacing is trimmed. Spaces between pipes and cell content are trimmed, and cells in one column do not need to match in length.[1] Padding the columns so they line up in your editor is purely for the human reading the source.
The delimiter row is hyphens and colons. Its cells contain only hyphens, with an optional leading or trailing colon, or both, to indicate left, right or center alignment respectively.[1] GitHub's docs add a practical note: there must be at least three hyphens in each column of the header row.[2] Use three or more to satisfy both.
Column alignment with colons
Alignment is set per column in the delimiter row. The GitHub docs show the three-column version:[2]
| Left-aligned | Center-aligned | Right-aligned |
| :--- | :---: | ---: |
| git status | git status | git status |
| git diff | git diff | git diff |
The spec shows what that looks like in HTML. In Example 199, the delimiter cells :-: and -----------: produce align="center" and align="right" on both the <th> and the matching <td> cells.[1] Note that the example's source, | abc | defghi | over :-: | -----------: over bar | baz, has no leading pipe on the delimiter row or the data row, and the table still parses.
Keep this table for reference. It covers the alignment syntax and the spec's own output for it.
| Delimiter cell | Colon position | Alignment | HTML in spec output |
|---|
| --- | None | No alignment set | No align attribute (Example 198) |
| :--- | Leading | Left | Not shown in the spec's examples |
| ---: | Trailing | Right | align="right" (Example 199) |
| :---: | Both | Center | align="center" (Example 199) |
One gap is worth stating plainly. The spec describes the leading colon as left alignment, but none of its table examples renders it, so the exact HTML for a left-aligned column is not shown there. Do not rely on any specific markup for it. Check the output in the renderer you ship to.
Escaping a pipe inside a cell
A pipe is the cell separator, so a literal pipe in your content needs a backslash. The spec says to include a pipe in a cell's content by escaping it, including inside other inline spans.[1] That last clause matters: escaping is still required inside inline code and inside bold. Example 200 is below, and its output cells hold f|oo, b <code>|</code> az and b <strong>|</strong> im.
| f\|oo |
| ------ |
| b `\|` az |
| b **\|** im |
The backslash is consumed: each output cell contains a bare |, with no backslash in sight.[1] GitHub's docs show the same fix in a small table of characters: the pipe row is written \|.[2]
This is the most common reason a table "loses" a column. If you document a command such as a | b in a cell, the unescaped pipe is read as a cell boundary. Escape it as a \| b.
Missing and extra cells in a row
The header row and the delimiter row must agree on the number of cells. The data rows are more forgiving. The spec states that the remaining rows may vary in the number of cells: fewer cells than the header means empty cells are inserted, and more means the excess is ignored.[1] Example 204, in the first block below, shows both in one table. The output has two body rows: bar with an empty second cell, then bar and baz.
# Example 204: ragged data rows
| abc | def |
| --- | --- |
| bar |
| bar | baz | boo |
# Example 202: text under the last row, then a blank line
| abc | def |
| --- | --- |
| bar | baz |
bar
bar
Read the output closely. The third cell of the last row, boo, is gone from the HTML. No error, no warning. If a value silently disappears from a rendered table, count the cells in that row against the header.
The header row is different. If the header and delimiter rows do not have the same number of cells, a table will not be recognized.[1] In Example 203 the source is | abc | def |, then | --- |, then | bar |.
The spec's output is a plain paragraph that contains the raw text of all three lines, pipes included: <p>| abc | def | followed by the other two lines and </p>.[1] If your table renders as a block of pipe-filled text, a mismatched delimiter row is the first thing to check.
Where a table ends
A table has no closing marker. The spec says the table is broken at the first empty line, or at the beginning of another block-level structure.[1] Example 201 puts a block quote line, > bar, directly under the last row of a two-column table.
The output is a complete table followed by a separate <blockquote> containing <p>bar</p>.[1] The block quote did not become a row.
Now the trap, shown in the second half of the block above. Example 202 puts a plain line of text directly under the last row, then a blank line, then another line.
The first bar is absorbed into the table as a new row with an empty second cell. The blank line ends the table, and the last bar becomes a paragraph.[1] So a line of text with no pipes, written directly beneath a table, joins the table as a row. Put a blank line after your last row and before any following paragraph.
The same logic applies on the way in. GitHub's docs say you must include a blank line before your table in order for it to render correctly.[2] Leave a blank line on both sides.
What a cell can and cannot hold
Cells hold inline content. The spec is blunt about the limit: block-level elements cannot be inserted in a table.[1] That rules out headings, block quotes and code blocks inside a cell, and it fits how the spec defines a table as a leaf block type.[1]
Inline formatting is fine. GitHub's docs list links, inline code blocks and text styling as usable within a table, for example git status and **haven't been** inside cells.[2]
If you need a list, a long code sample or several paragraphs per entry, a table is the wrong container. Use a heading and a list per item, or write the table in raw HTML where your renderer allows it. Test that route in your own pipeline, because this guide does not cover raw HTML tables.
Reference: what breaks a Markdown table
This is the troubleshooting table. Each row cites the spec example or GitHub doc that confirms it.
| Symptom | Cause | Fix | Source |
|---|
| Raw pipes show up as plain text | Header and delimiter rows have different cell counts | Match the cell count in both rows | Example 203 |
| A value vanishes from a row | The row has more cells than the header; the excess is ignored | Add a header column or remove the cell | Example 204 |
| An unexpected empty cell | The row has fewer cells than the header; empty cells are inserted | Add the missing cells | Example 204 |
| Text after the table becomes a row | A plain line directly under the last row joins the table | Add a blank line after the last row | Example 202 |
| Table stops early | An empty line or another block-level structure began | Keep every row on consecutive lines | Examples 201, 202 |
| A pipe splits one cell into two | Unescaped pipe in content | Write \|, even inside code or bold | Example 200, GitHub docs |
| Table does not render on GitHub | No blank line before the table | Add a blank line above the header row | GitHub docs |
| A heading or code block in a cell fails | Block-level elements cannot be inserted in a table | Use inline formatting only | GFM spec section 4.10 |
A header-only table
A table with no data rows is valid. The spec allows zero or more data rows, and says that if there are no rows in the body, no <tbody> is generated in the HTML output.[1] Example 205 is just | abc | def | over | --- | --- |, and its output is a <table> with a <thead> and nothing else.
This is handy for templates: a README that ships with a header and delimiter row ready for a contributor to fill in.
Markdown table support is an extension
The original CommonMark specification does not define tables. Version 0.31.2, dated 2024-01-28, lists nine leaf block types in its table of contents: thematic breaks, ATX headings, setext headings, indented code blocks, fenced code blocks, HTML blocks, link reference definitions, paragraphs and blank lines.[3] Tables are not among them. The GFM spec adds one explicitly: GFM enables the table extension, where an additional leaf block type is available.[1]
Practical consequence: a parser that implements only core CommonMark will not recognize your table and will print it as a paragraph, the same result as Example 203. Before you rely on table syntax in a static site generator, a docs platform or an email tool, confirm that its Markdown flavor enables tables. Do not assume it.
One more caveat on sources. The GFM spec page opened for this guide is version 0.29-gfm, dated 2019-04-06.[1] GitHub's own documentation page is the more current reference for how github.com behaves, and it is consistent with the spec on every point cited above.[2] There is one visible difference in emphasis. The docs require at least three hyphens per header column, while the spec's Example 199 uses a delimiter cell as short as :-:.[1][2] Writing three hyphens satisfies both.
Write and preview a table
Draft the table in the Markdown editor, watch the live preview, and use the troubleshooting table above when the preview shows raw pipes or a missing value. The editor's parser is not checked against the spec examples in this guide (unconfirmed), so confirm the final output in the renderer you publish to.
Quick reference
A Markdown table is a header row, a delimiter row, and zero or more data rows. Cells are split by pipes. The delimiter row holds hyphens, with colons for alignment: a colon on the left, the right or both sides. Escape a literal pipe as \|. Keep header and delimiter cell counts equal. Extra cells in data rows are dropped, and missing ones become empty. A blank line ends the table, and block-level elements cannot go inside a cell. Core CommonMark has no tables, so check that your renderer supports the GFM extension.
Sources
3. CommonMark Spec, version 0.31.2 (accessed November 24, 2026)
Originally published at wowhow.cloud
Top comments (0)