Markdown Toolbox Logo Markdown Toolbox
Home
Blog

How do I add borders to a table in Markdown?

2024-08-05

Short version

Markdown does not support table borders directly; use HTML instead:

<table>
<tr>
<th>Name</th>
<th>Age</th>
<th>Location</th>
</tr>
<tr>
<td>John</td>
<td>30</td>
<td>USA</td>
</tr>
<tr>
<td>Jane</td>
<td>25</td>
<td>Canada</td>
</tr>
</table>

Long version

1. Understanding Markdown Limitations

Markdown itself does not have native support for adding borders to tables. However, it provides a way to create simple tables using pipes and dashes for columns and rows.

2. Using HTML for Tables with Borders

If borders are needed, you can use standard HTML instead of Markdown syntax. Here's how:

<table>
<tr>
<th>Name</th>
<th>Age</th>
<th>Location</th>
</tr>
<tr>
<td>John</td>
<td>30</td>
<td>USA</td>
</tr>
<tr>
<td>Jane</td>
<td>25</td>
<td>Canada</td>
</tr>
</table>

This will render a table with borders, regardless of Markdown renderer.

3. Styling Borders with CSS

If you are embedding Markdown within a webpage, you can style table borders using CSS. Use the following CSS rule to add borders to all tables:

table,
th,
td {
    border: 1px solid black;
    border-collapse: collapse;
}

Adding this CSS will enhance the visual aspect of the Markdown table when rendered in a web environment.