In the previous module, we learned how to add pictures, audio, and videos to our webpages.
In this module, we will learn how to organize information using tables. Tables help us arrange information into rows and columns, just like a school timetable or a football score sheet.
A table is a way of organizing information into rows and columns.
You see tables every day in school timetables, examination results, attendance registers, and football league tables.
Imagine a chocolate bar divided into small squares. Each square is like a cell in a table.
We use the <table> tag to create a table.
<table> </table>
Everything inside the table tag becomes part of the table.
Rows go from left to right. We use the <tr> tag to create rows.
<table>
<tr>
</tr>
</table>
Think of rows as seats in a classroom. Students sit side by side in the same row.
Cells hold the information inside a table. We use the <td> tag for table data.
<table border="1">
<tr>
<td>Tolu</td>
<td>10</td>
</tr>
</table>
| Tolu | 10 |
Table headings tell us what information is in each column. We use the <th> tag.
<table border="1">
<tr>
<th>Name</th>
<th>Age</th>
</tr>
<tr>
<td>Tolu</td>
<td>10</td>
</tr>
</table>
| Name | Age |
|---|---|
| Tolu | 10 |
Let's create a simple school timetable.
<table border="1">
<tr>
<th>Time</th>
<th>Subject</th>
</tr>
<tr>
<td>8:00 AM</td>
<td>Mathematics</td>
</tr>
<tr>
<td>9:00 AM</td>
<td>English</td>
</tr>
</table>
Tables are like shelves in a library. Each shelf stores information in an organized way.
Sometimes we want one cell to take up more than one column. We use the colspan attribute.
<table border="1">
<tr>
<th colspan="2">
My Report Card
</th>
</tr>
</table>
The heading stretches across two columns.
Sometimes we want one cell to cover more than one row. We use the rowspan attribute.
<td rowspan="2">
Football
</td>
This cell will cover two rows.
<!DOCTYPE html>
<html>
<head>
<title>My Class List</title>
</head>
<body>
<h1>My Class List</h1>
<table border="1">
<tr>
<th>Name</th>
<th>Favourite Subject</th>
</tr>
<tr>
<td>Tolu</td>
<td>Science</td>
</tr>
<tr>
<td>Amina</td>
<td>Mathematics</td>
</tr>
</table>
</body>
</html>
Fill in the blanks:
Create a table showing:
Use table headings.
Fix the missing tags below:
<table border="1">
_____
_____ Name _____
_____ Age _____
_____
_____
_____ Tolu _____
_____ 10 _____
_____
</table>
Use:
Create a webpage called myschooltimetable.html.
Add:
Create a football score table with:
Add at least three teams.