How to create tables in Markdown?

The table consists of rows and columns. Rows are divided into table header and table body. In Markdown, pipes(|) are used to separate each cell, and at least three dashes are used to separate the table header and body. The general structure of a table in Markdown is like this:

Table Header
Alignment Row
Rows having data
| Table  | Header |
| ------ | ------ |
| Cell 1 | Cell 2 |
| Cell 3 | Cell 4 |

The rendered output will look like this:

Table Header
Cell 1 Cell 2
Cell 3 Cell 4

The width of cells may vary, but the rendered output will be the same.

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

It is important to note that outer pipes are optional, and you can omit them.

How to align text in the columns in Markdown?

With the help of a colon, you can control the alignment of columns. For example, suppose a colon is placed at the beginning of hyphens. In that case, those columns will be left-aligned, and if a colon is written at the end of hyphens, then the content of those columns will be right-aligned. But when a colon is placed on both sides of the hyphens, that column will be centred-aligned.

| left-aligned | centred-aligned | right-aligned |
| :---         | :---:           | ---:          |
| These cells  | These cells     | These cells   |
| are          | are             | are           |
| left-aligned | centred-aligned | right-aligned |

The rendered output will look like this:

left-aligned centred-aligned right-aligned
These cells These cells These cells
are are are
left-aligned centred-aligned right-aligned