How to Make a Table in HTML
An HTML table is a <table> made of rows, <tr>, and each row is made of cells: <th> for a header cell and <td> for a data cell. The browser lines the cells up into columns for you.
Syntax
<table>
<tr>
<th><heading></th>
</tr>
<tr>
<td><data></td>
</tr>
</table>
| Part | What it does |
|---|---|
<table> | The table. |
<tr> | A table row. Every cell goes inside a row. |
<th> | A header cell, for the heading of a column. |
<td> | A data cell. |
<heading>, <data> | The text in each cell. |
Each row should have the same number of cells, one for each column. MDN's table page covers the other table elements.
The Example
The example is a table of two public holidays, with the columns Date and Holiday.
Step 1: Write the Code
Create a file named index.html in a text editor, such as Visual Studio Code:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Holidays</title>
</head>
<body>
<table>
<tr>
<th>Date</th>
<th>Holiday</th>
</tr>
<tr>
<td>1 January</td>
<td>New Year's Day</td>
</tr>
<tr>
<td>25 December</td>
<td>Christmas Day</td>
</tr>
</table>
</body>
</html>
Step 2: Open It in a Browser
Double-click index.html. It opens in your browser:

The screenshot comes from Chromium 159, the open-source browser that Chrome is built on.
What Happened
- The cells lined up in two columns, each as wide as its longest text.
- The
thcells are bold and centered, and thetdcells are normal text on the left. Those are the browser's defaults: Chromium gavetha font weight of 700 and centered text. - The table has no lines. A table only gets borders from CSS.
- The browser added a
tbodyelement around the rows, although the file has none: in the page Chromium built, all three rows were inside atbody.
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
| Writing text in a row without a cell | The text jumps out of the table: Two holidays, written between two rows, appeared above the table | Put all text in a th or a td |
| Giving one row more cells than the others | The extra cell starts a new column with no heading: a third cell, Public, in the 1 January row sat in a column of its own, with nothing above it | Give each row one cell per column, or join cells with colspan |
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
| Some text shows above the table | It isn't inside a cell | Move it into a td |
| The table has no lines | Tables have no borders by default | Add borders with CSS |
FAQ
How do I add borders?
With CSS, for example in a style element: th, td { border: 1px solid #999999; } gave every cell a 1-pixel grey border.
How do I make a cell span two columns?
Give it colspan="2". In a test row with one such cell, the cell stretched across both columns, as wide as the two cells above it together.
What is tbody for?
It groups the rows that make up a table's body. You can leave it out, as the example does, and the browser adds it for you.
Conclusion
Rows of cells, th for headings and td for data, are all an HTML table needs. Keep every piece of text inside a cell, give each row the same number of columns, and add lines with CSS.
Additional Resources
- table: The Table element, on MDN.
- tr: The Table Row element, on MDN.
