Markdown Toolbox Logo Markdown Toolbox
Home
Blog

How do I center columns in Markdown tables?

2024-08-12

Short version

Use colons : in the separator line to center columns:

| Name | Age | Location |
|:----:|:---:|:--------:|
| John | 30  | USA      |
| Jane | 25  | Canada   |

Long version

1. Understanding Column Alignment

Columns in Markdown tables can be aligned to the left, right, or center. The alignment of the columns is determined by the position of colons in the separator line.

2. Centering a Column

To center a column, place colons on both sides of the dashes in the separator line.

Example:

| Name | Age | Location |
|:----:|:---:|:--------:|
| John | 30  | USA      |
| Jane | 25  | Canada   |

This will center the 'Name', 'Age', and 'Location' columns in the final rendered Markdown table.

3. Using Mixed Alignments

You can combine different alignments as needed. For example, to left-align one column and center others:

| Name | Age | Location |
|:-----|:---:|:--------:|
| John | 30  | USA      |
| Jane | 25  | Canada   |

With this method, the 'Name' column will be left-aligned, while 'Age' and 'Location' will be centered.