BudiBadu Logo
Samplebadu

Markdown by Example: Tables

CommonMark / GFM

Tables allow you to display data in rows and columns. This sample shows the syntax for creating and aligning tables.

Code

| Header 1 | Header 2 | Header 3 |
| :--- | :---: | ---: |
| Left | Center | Right |
| Text | Text | Text |

Simple table (outer pipes optional):

Header A | Header B
--- | ---
Cell 1 | Cell 2
Cell 3 | Cell 4

Explanation

Tables are not part of the original Markdown spec but are included in GFM and most other flavors. You create a table using hyphens - for the separator line and pipes | to separate columns. The first row is the header. The second row separates the header from the body and defines alignment.

Colons : in the separator line control text alignment. :--- aligns left (default), :---: centers the text, and ---: aligns right. You don't need to align the pipes vertically in the source code for it to work, but it makes the raw file much easier to read.

Tables in Markdown are somewhat limited. You cannot easily have multi-line cell content, merged cells, or complex formatting inside cells. For those use cases, you usually have to fall back to using raw HTML <table> tags.

Code Breakdown

2
| :---: | The colons on both sides indicate center alignment for that column.
1
| Header 1 | defines the column headers. This row is required.