Markdown Tables

Markdown logo

Tables are an great way to structure data and information into a readable format. Although tables are not part of the original Markdown specification, tables are supported in GitHub Flavored Markdown and many other Markdown flavors.

Basic table syntax

Markdown tables are created using pipes | between columns and hyphens - to create a header row:

| Header 1 | Header 2 | Header 3 |
|----------|----------|----------|
| Row 1    | Data     | Data     |
| Row 2    | Data     | Data     |
| Row 3    | Data     | Data     |

Rendering in the document as:

Header 1Header 2Header 3
Row 1DataData
Row 2DataData
Row 3DataData

Aligning columns

A colon : is used in the header row to align the content inside the columns:

  • Align left (default): |-------|
  • Align center: |:-----:|
  • Align right: |-------:|
| Left-aligned | Center-aligned | Right-aligned |
|:-------------|:--------------:|--------------:|
| Left         | Center         | Right         |
| Left         | Center         | Right         |

Aligning the text in each column as follows:

Left-alignedCenter-alignedRight-aligned
LeftCenterRight
LeftCenterRight

Simplified syntax

The pipes | at the beginning and end of each row are optional:

Header 1 | Header 2
--- | ---
Data | Data
Data | Data

Displaying as a regular table:

Header 1Header 2
DataData
DataData

This still renders as a properly formatted table. However, for readability in the source file, it's generally recommended to:

  1. Use the outer pipes.
  2. Align the pipe characters vertically.
  3. Use at least three hyphens (---) for each column in the header row.

Formatting table content

Table cells can include most formatting options:

| Type | Output |
|------------|---------|
| Italic     | *Italic text* |
| Bold       | **Bold text** |
| Code       | `code` |
| Link      | [Click me](https://learn-webdevelopment.com/course/markdown/more-advanced-features/markdown-tables) |

Rendering as:

TypeOutput
ItalicItalic text
BoldBold text
Codecode
LinkClick me

Escaping Pipe Characters

If you need to include a pipe character | within your table content, you can escape it with a backslash \:

| Heading 1 | Heading 2 |
|----------|----------|
| Data   | Data   |
| Data with \| pipe | Data |
Heading 1Heading 2
DataData
Data with | pipeData

Empty Cells

To create an empty cell, simply leave the cell empty between the pipes:

| Heading 1 | Heading 2 | Heading 3 |
|----------|----------|----------|
| Data     |          | Data     |
|          | Data     | Data     |

Rendering as:

Heading 1Heading 2Heading 3
DataData
DataData