How to make a table in HTML
<table>, <tr>, <th> and <td>, borders that look right, merged cells, column widths, striped rows, and tables that fit on a phone screen.
To make a table in HTML, wrap it in <table>, put each row in <tr>, and put each cell in <td>: <table><tr><td>Jan</td><td>$1,200</td></tr></table>. Use <th> instead of <td> for header cells. A table with no CSS has no borders, so add one line of CSS to see the grid.
The basic tags
- ✓<table> wraps the whole table.
- ✓<tr> is one row. Every cell sits inside a <tr>.
- ✓<th> is a header cell: bold and centered by default, and screen readers announce it with each cell under it.
- ✓<td> is a normal data cell.
- ✓<thead>, <tbody> and <tfoot> group the header rows, body rows and a totals row. They are optional, but they make styling and printing easier: a long table repeats its <thead> on each printed page.
- ✓<caption> goes right after <table> and gives the table a visible title.
A complete example
<table><caption>Q3 sales</caption><thead><tr><th>Month</th><th>Orders</th><th>Revenue</th></tr></thead><tbody><tr><td>July</td><td>42</td><td>$3,150</td></tr><tr><td>August</td><td>51</td><td>$3,820</td></tr></tbody><tfoot><tr><td>Total</td><td>93</td><td>$6,970</td></tr></tfoot></table>. Each row needs the same number of cells, or the columns shift.
Add borders
- ✓table { border-collapse: collapse; } turns the double lines between cells into single lines.
- ✓th, td { border: 1px solid #ccc; padding: 8px 12px; } draws the grid and gives the text room.
- ✓th { background: #f3f4f6; text-align: left; } makes the header row stand out.
- ✓The old border="1" attribute on <table> still works but cannot set color or thickness; use CSS.
Merge cells
- ✓Across columns: <td colspan="2"> makes one cell two columns wide. Remove one <td> from that row to match.
- ✓Down rows: <td rowspan="3"> makes one cell three rows tall. Remove one cell from each of the next two rows.
- ✓If a row looks shifted after merging, count the cells: colspan and rowspan values plus plain cells must add up to the same total in every row.
Widths, alignment and striped rows
- ✓Full width: table { width: 100%; }.
- ✓One column wider: give its <th> a width, such as <th style="width: 40%">.
- ✓Equal columns that ignore content length: table { table-layout: fixed; }.
- ✓Right-align numbers so digits line up: td.num { text-align: right; } with class="num" on those cells.
- ✓Striped rows: tbody tr:nth-child(even) { background: #f9fafb; }.
- ✓Highlight a row on hover: tbody tr:hover { background: #eef2ff; }.
Tables on phones
A table with many columns is wider than a phone screen and pushes the whole page sideways. Wrap it in a scrolling box: <div style="overflow-x: auto;"><table>…</table></div>. The table then scrolls on its own while the rest of the page stays put. Add white-space: nowrap; to cells that should not wrap, such as dates and prices.
When to use a table
Use tables for data with rows and columns: prices, schedules, results, comparisons. Do not use them to lay out a page into columns; that was common before CSS, but it breaks on phones and confuses screen readers. For page layout use display: flex or display: grid.
Pages made with AI tools
Claude, ChatGPT and other tools usually style tables with Tailwind classes: border-collapse, border, px-4 py-2 (cell padding), text-left, odd:bg-gray-50 or even:bg-gray-50 (stripes) and overflow-x-auto on a wrapping <div>. To change a table, ask for the change in plain words ("right-align the revenue column") or edit those classes directly.
Share the table as a link
With FileShare Pro you upload the .html file from the dashboard, copy the link and send it; it opens as a page in any browser and the person opening it needs no account. When the numbers change, edit the file and upload it to the same link. Related: share a sortable HTML table as a link and how to make a list in HTML. Sign up free to share your first page.
Frequently asked
Wrap the table in <table>, each row in <tr>, and each cell in <td> (or <th> for header cells). Add CSS such as th, td { border: 1px solid #ccc; } to show the grid.
Use CSS: table { border-collapse: collapse; } and th, td { border: 1px solid #ccc; padding: 8px; }. border-collapse removes the double lines between cells.
Use colspan to merge across columns (<td colspan="2">) and rowspan to merge down rows (<td rowspan="2">). Remove the cells the merged cell now covers.
Wrap the table in <div style="overflow-x: auto;"> so it scrolls sideways inside the box instead of widening the whole page.
Drop the file, copy the link — live in seconds, free plan included.
Start sharing free