Markdown Table Syntax Reference
The smallest complete description of GitHub Flavored Markdown tables — nothing more than you need to read and fix them.
Header and separator rows
A table needs at least a header row and a separator row of dashes. The separator is what tells the renderer "this is a table" — without it, pipes render as plain text:
| Product | Qty |
|:---------|:---:|
| Widget A | 10 |Column alignment
Colons in the separator row control alignment:
:---— left-aligned (the default).:---:— centered.---:— right-aligned, ideal for numbers and prices.
Cell content rules
- Pipes inside a cell must be escaped as
\|, or the renderer sees extra columns. - Line breaks must be written as
<br>; a literal newline ends the row. - Inline formatting — links,
code spans, bold — works inside cells. - Outer pipes at the line edges are optional but recommended for readability.
What GFM tables do not support
No merged cells, no nested tables, no block elements (lists, headings, fenced code) inside cells. When data needs that structure, simplify the table or link out to the full source. Tables that violate these rules are covered in why Markdown tables break and how to fix them.
The CommonMark & GFM Specification Architecture
Original Markdown as created by John Gruber in 2004 contained no native syntax for tables. In response to divergent parser implementations across PHP Markdown Extra, MultiMarkdown, and Pandoc, GitHub formalized theGFM Table Extension (Section 4.12) as a strict layer on top of CommonMark 0.29.
The parser uses a deterministic lexical state machine:
- Phase 1: Header Row Detection: The parser scans lines for pipe-delimited text. Outer boundary pipes (leading and trailing) are syntactically optional according to the spec, but omitting them often causes ambiguity in non-GFM renderers (such as Bitbucket or generic static site generators).
- Phase 2: Delimiter Row Validation: The line immediately following the header must contain only pipes, dashes, optional colons, and whitespace. A single alphanumeric character or invalid punctuation mark invalidates the entire block.
- Phase 3: Body Row Ingestion: Each subsequent line is segmented into cell tokens. If a row contains fewer cells than the header, the parser automatically pads missing trailing cells with empty strings. If a row contains more cells than the header, excess cells are silently discarded by the GFM engine.
Escaping Characters: The Delimiter Precedence Hierarchy
Certain characters hold special syntactic meaning in Markdown and must be handled carefully when embedded within tabular cells:
- Literal Pipe (
|): Always write as\|. Without the backslash escape, the lexer splits the cell prematurely. - Raw Angle Brackets (
<and>): If your table documents HTML tags or generic types (e.g.List<String>), wrap the term in inline code backticks:`List<String>`. Bare angle brackets can trigger the HTML block parser, stripping subsequent table rows. - Backticks Inside Code Spans: To display a literal backtick inside a table cell code snippet, use double backticks with space padding:
`` ` ``. - Asterisks and Underscores: Unescaped pairs like
*data*will format as italics. If you want literal asterisks, escape them as\*data\*.
Whitespace Padding vs Rendered Output
Many developers spend hours manually padding columns with spaces so the raw plain-text source file looks like a clean ASCII grid:
| ID | Item Name | Unit Price |
|:-----|:---------------------|-----------:|
| 101 | Mechanical Keyboard | $129.00 |
| 102 | Optical Gaming Mouse | $59.50 |While column padding makes the raw git diff significantly more readable, it has zero effect on rendered HTML. A compacted table with no internal spacing renders identically:
|ID|Item Name|Unit Price|
|:---|:---|---:|
|101|Mechanical Keyboard|$129.00|
|102|Optical Gaming Mouse|$59.50|Our converter automatically generates properly padded whitespace tables by calculating the maximum character width across every column.
When to Drop Back to Raw HTML Tables
Markdown tables are intentionally constrained to 2D flat structures. If your dataset requires any of the following features, you must use standard HTML <table> syntax instead:
- Cell Spanning: Spanning multiple columns (
colspan="2") or rows (rowspan="3"). - Nested Sub-tables: Embedding a mini secondary table inside a single parent cell.
- Complex Block Content: Multi-paragraph explanations, blockquotes, or syntax-highlighted code blocks inside cells.
GitHub Flavored Markdown fully renders raw HTML tables in README files and issues, making HTML the standard escape hatch for advanced documentation matrices.
Right-to-Left (RTL) Scripts in Markdown Tables
When documenting datasets containing Arabic, Hebrew, or Persian text alongside English parameters, bidirectional text layout can cause visual confusion in plain-text editors:
- Delimiter Orientation: The structural pipe characters and hyphens must remain standard ASCII characters. Do not use full-width or Arabic typographical punctuation.
- Explicit Alignment Tags: Set column alignment to right (
---:) for RTL language columns. While the browser layout engine will order the glyphs right-to-left, explicit GFM right-alignment ensures the entire cell content sits against the right column border. - BiDi Isolation: Wrap mixed English and Arabic strings inside HTML
<bdi>tags if directional spillover causes numbers or trailing parentheses to jump to the wrong side of the cell.
Browser Performance & DOM Memory Limits
While Markdown source files are lightweight, browsers convert table tokens into live DOM tree nodes:
- The 1,000-Row Ceiling: A 1,000-row table with 8 columns produces over 8,000
<td>DOM elements. In client-side SPAs or GitHub mobile apps, this can cause significant scrolling lag and layout thrashing. - Virtualization vs Pagination: For datasets exceeding 200 rows, do not embed the entire table in a static Markdown document. Instead, publish the top 20 representative rows as a preview table, and provide a direct download link to the complete raw
.csvor.xlsxfile.
GFM Table Syntax Cheat Sheet & Delimiter Reference
Keep this reference table handy when authoring or debugging complex Markdown documentation tables across your projects:
| Feature | Syntax Example | Parsed Result | GFM Compliance Rule |
|---|---|---|---|
| Left Alignment | | :--- | | Left-aligned text | Default when colons are omitted |
| Center Alignment | | :---: | | Centered text | Ideal for icons, badges, and statuses |
| Right Alignment | | ---: | | Right-aligned text | Mandatory for currencies and numeric figures |
| Literal Pipe | \| | Displays as | | Prevents cell fragmentation |
| In-Cell Line Break | Line 1<br>Line 2 | Line 1 Line 2 | Literal newlines terminate table row |
Markdown Dialect Comparison: GFM vs Pandoc vs MultiMarkdown
Different markdown compilers introduce unique extensions to tabular syntax:
- GitHub Flavored Markdown (GFM): The industry baseline for developers. Simple pipe-delimited syntax with colon alignments. No native multiline cell or spanning support.
- MultiMarkdown (MMD): Supports table captions (
[Table caption]) and column/row spanning via paired pipes (||), but requires specialized MMD compilers. - Pandoc Pipe Tables: Supports block markdown inside grid tables (delimited by
+---+---+borders), enabling multiple paragraphs and bullet lists inside individual cells. However, GitHub does not render Pandoc grid tables. - PHP Markdown Extra: Introduces class and ID attributes for tables (e.g.
{.table-striped}), enabling CSS framework integration in older CMS platforms like WordPress or Drupal.
Best Practices for Collaborative Git Workflows
When multiple developers edit Markdown tables in shared pull requests, merge conflicts frequently arise along delimiter boundaries:
- One Entity Per Row: Avoid concatenating related items into a single row. Flat, atomic rows minimize Git line merge collisions.
- Sort Rows Deterministically: If your table documents API endpoints or dependency packages, keep rows sorted alphabetically so newly added rows append to unambiguous positions rather than generating random diff shifts.
- Automated Git Pre-Commit Hooks: Configure Husky or Lefthook pre-commit hooks to run table alignment linters automatically before staging commits, ensuring your entire repository adheres to uniform GFM formatting standards across every documentation branch.
Related guides
Frequently asked questions
How do I align a Markdown table column left, center, or right?
Use colons in the separator row: :--- for left, :---: for center, ---: for right. Alignment is a rendering hint — the raw text stays readable either way.
How do I put a line break inside a table cell?
Use an explicit <br> tag. A literal newline ends the table row in most renderers, so multiline content must be joined onto one line.
Do Markdown tables support merged cells?
No. GitHub Flavored Markdown has no colspan or rowspan. Repeat the value in each cell or restructure the data so every row has the same flat column layout.