Open In App

Markdown Tables

Last Updated : 21 Mar, 2025
Summarize
Comments
Improve
Suggest changes
Share
Like Article
Like
Report

Markdown tables are a great way to organize and display data in a clean, readable format. They are widely used in documentation, README files, and other text-based content. In this guide, we will break down how to create and format tables in Markdown step by step.

Basic Table Structure

Markdown tables are created using pipes (|) to separate columns and hyphens (-) to define the header row. Here’s the basic structure:

  1. Header Row: The first row contains column names.
  2. Divider Line: The second row uses hyphens to separate the header from the data.
  3. Data Rows: The rows below the divider contain the actual data.

Markdown table syntax is quite straightforward. A basic table is composed of a row of headers, followed by a divider line, and then the table’s rows:

| Name  | Age |  City    |
|-------|-----|-------|
| Alice | 25 | New York |
| Bob | 30 | London |

When rendered, the output will look like this:

NameAgeCity
Alice25New York
Bob30London

Creating Simple Tables

To create a table, follow these steps:

  1. Use pipes (|) to separate columns.
  2. Use hyphens (-) in the second row to define the header divider.
  3. Add your data rows below the divider.

Here's a basic example:

| Product  | Price | Stock  |
|----------|-------|--------|
| Laptop | $800 | 10 |
| Phone | $500 | 15 |
| Headset | $50 | 30 |

The table , Once is rendered the Output will look like this:

ProductPriceStock
Laptop$80010
Phone$50015
Headset$5030

Customizing Table Content

You can style text inside Markdown table cells just like regular Markdown. This includes making text bold, italic, monospaced, or adding links.

  • Bold: **text**
  • Italic: *text*
  • Code: `code`
  • Links: [text](link)

Example:

| Feature   | Description                | Example          |  
|-----------|----------------------------|------------------|
| **Bold** | Highlights important text | **Important** |
| *Italic* | Emphasizes words/phrases | *Emphasized* |
| `Code` | Displays inline code | `print("Hello")` |
| [Link](#) | Adds clickable hyperlinks | [Click me](#) |

The rendered table will appear as follows:

FeatureDescriptionExample
BoldHighlights important textImportant
ItalicEmphasizes words or phrasesEmphasized
CodeDisplays inline codeprint("Hello")
LinkAdds clickable hyperlinksClick me

Handling Empty Cells

Markdown tables don’t support merging cells (like in HTML). Each cell is treated separately. But if you want an empty space, just leave it blank.

Example:

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

When rendered, the output will look like this:

Header 1Header 2
Cell 1
Cell 3Cell 4

Aligning Text in Markdown Tables

You can align text in Markdown table columns to the left, right, or center by placing a colon (:) in different positions within the header divider row.

  • Left-aligned: :--- (Colon on the left)
  • Right-aligned: ---: (Colon on the right)
  • Center-aligned: :---: (Colons on both sides)

Example:

| Left Align | Center Align | Right Align |
|:----------|:-----------:|-----------:|
| Apple | Banana | Cherry |
| Dog | Elephant | Fox |
| 10 | 20 | 30 |

When rendered, the output will look like this:

Left AlignCenter AlignRight Align
AppleBananaCherry
DogElephantFox
102030

Conclusion

Markdown tables provide a simple and effective way to organize and present structured data. While they don’t support advanced features like cell merging, you can still format text, align content, and handle empty cells to enhance readability.

By using pipes (|) and hyphens (-), along with alignment tricks (:), you can create well-structured tables for documentation, READMEs, and other text-based content. If you need additional customization, some Markdown flavors allow HTML integration for more flexibility.


Article Tags :

Similar Reads