Tables
Tables show data in rows and columns. <table> wraps the table, <tr> makes a row, <th> a heading cell and <td> a normal cell.
Tables are perfect when data has rows and columns - a timetable, marks of students, a price comparison of phones, an invoice. Each row (<tr>) is one record; each cell (<td>) is one value. The first row usually uses <th> heading cells, which browsers show in bold and screen readers announce as headings.
For bigger tables, group the heading row in <thead> and the data rows in <tbody>. On phones, wide tables can overflow - wrapping them in a box with overflow-x: auto (CSS) lets visitors scroll sideways.
Example
<!DOCTYPE html>
<html>
<head>
<style>
table { border-collapse: collapse; }
th, td { border: 1px solid #999; padding: 6px 12px; }
th { background: #f1f1f1; }
</style>
</head>
<body>
<table>
<tr><th>Phone</th><th>Price</th><th>Battery</th></tr>
<tr><td>Model A</td><td>₹12,999</td><td>5000 mAh</td></tr>
<tr><td>Model B</td><td>₹15,499</td><td>4500 mAh</td></tr>
</table>
</body>
</html>▶ Try it yourselfUse tables only for data, like a price comparison. Do not use them to lay out a whole page; CSS does that much better.
Key points
<table>><tr>><th>/<td>.- Use tables for data, not for page layout.
- Headings in
<th>help everyone read the table.
📝 Test yourself
1. Which element creates a table row?
2. What should tables be used for?
3. Fill in the tag for a heading cell:
<>
