How to Align Tables Left, Right, or Center in Markdown
How can we left-align, right-align, or center-align our table contents in a Markdown page?
Different applications have different defaults for table content alignment, but we can force each column to follow some specified alignment.
Left-align (:--
)
We can left-align by adding :--
in the second row.
| Header 1 | Header 2 | Header 3 |
|:---------|:---------|:---------|
| 1 | 2 | 3 |
Header 1 | Header 2 | Header 3 |
---|---|---|
1 | 2 | 3 |
Right-align (--:
)
We can right-align by adding --:
in the second row.
| Header 1 | Header 2 | Header 3 |
|---------:|---------:|---------:|
| 1 | 2 | 3 |
Header 1 | Header 2 | Header 3 |
---|---|---|
1 | 2 | 3 |
Center-align (:-:
)
We can center-align by adding :-:
in the second row.
| Header 1 | Header 2 | Header 3 |
|:--------:|:--------:|:--------:|
| 1 | 2 | 3 |
Header 1 | Header 2 | Header 3 |
---|---|---|
1 | 2 | 3 |
Mix and match. Since each cell has its own alignment specifier, we can use different alignments for each column.