When people hear “HTML tables,” many immediately think of old-school computer classes — grey boxes, lots of tags, and the feeling that it’s complicated and boring. But actually, it’s really simple! An HTML table is just a neat way to organize information into rows and columns.
Think of a table in your notebook: headings at the top, and rows of data below. HTML works the same way. Everything starts with one tag that tells the browser: “Hey, a table is coming!”
And that tag is <table>.
Inside it, we create rows (<tr> — table row) and cells. There are two types of cells:
<th> — a header cell (bold and centered by default),
<td> — a regular data cell.
Here’s an example of a simple table for a school schedule:
<table>
<tr>
<th>Lesson</th>
<th>Subject</th>
<th>Time</th>
</tr>
<tr>
<td>1</td>
<td>Math</td>
<td>08:30</td>
</tr>
<tr>
<td>2</td>
<td>History</td>
<td>09:20</td>
</tr>
<tr>
<td>3</td>
<td>English</td>
<td>10:10</td>
</tr>
</table>
Each <tr> is a horizontal row, and each <td> is a cell.
<table> — starts the table.
<tr> — creates a row.
<th> — adds a header cell.
<td> — adds a regular data cell.
That’s it — just four simple tags!
By default, tables have no visible lines — it’s just text. To make it look more like a real table, add the border attribute:
<table border="1">
<tr>
<th>Lesson</th>
<th>Subject</th>
<th>Time</th>
</tr>
<tr>
<td>1</td>
<td>Math</td>
<td>08:30</td>
</tr>
<tr>
<td>2</td>
<td>History</td>
<td>09:20</td>
</tr>
<tr>
<td>3</td>
<td>English</td>
<td>10:10</td>
</tr>
</table>
Now you can clearly see the borders around each cell.
You can adjust how your table looks by adding a few simple attributes:
border — adds a border around the table.<table border="1">
cellpadding — adds space inside cells.<table border="1" cellpadding="5">
cellspacing — adds space between cells.<table border="1" cellspacing="5">
width — sets the width of the table or a column.<table width="100%"> — makes the table full width.
align — aligns the table (left, right, or center).<table align="center">
bgcolor — adds background color to the table or a cell.<table bgcolor="#f2f2f2"> or <td bgcolor="lightyellow">
colspan and rowspan — merge cells horizontally or vertically.
<td colspan="2">Text</td>
Back in the day, people even used tables to design entire websites (no kidding!). Today, tables are used only for actual tabular data — like price lists, schedules, or reports.
If you want your table to look prettier, you can use CSS styles — but that’s a topic for another lesson.
Knowledge Check: HTML Basics Test
159
HTML from Scratch: Adding Audio and Video to Your Website — For Beginners. Lesson #26
206
HTML from Scratch: The download Attribute in HTML5 (for downloading files). Lesson #25
281
HTML from Scratch: Commenting in HTML. Lesson #24
686
HTML from Scratch: The DOCTYPE Tag. Lesson #23
250
HTML from Scratch: Anchor Links in HTML. Lesson #7 10963
HTML from Scratch: How to Create a Horizontal Line in HTML. Lesson #10 1659
HTML from Scratch: How to Add Links in HTML. Lesson #6 741
HTML from Scratch: Basics for Beginners. Lesson #1 736
HTML from Scratch: Commenting in HTML. Lesson #24 686
Leave a Reply