Chapter 8: Creating Tables in HTML

Tables in HTML are used to display data in a structured format using rows and columns—like a spreadsheet or data grid. This is helpful for showing schedules, price lists, results, or any information that fits a tabular form.

Why Use Tables?

Basic Table Structure

<table>
  <tr>
    <th>Heading 1</th>
    <th>Heading 2</th>
  </tr>
  <tr>
    <td>Row 1, Col 1</td>
    <td>Row 1, Col 2</td>
  </tr>
</table>

Explanation of Tags

TagMeaningUse
<table>Table elementWraps the entire table
<tr>Table RowDefines a row in the table
<th>Table HeaderDefines a heading cell
<td>Table DataDefines a normal data cell

Example: Student Marksheet

NameMathScienceEnglish
Ali859088
Zara789582

Advanced: Merging Cells

<td colspan="2">Merged Cell</td>
<td rowspan="2">Merged Cell</td>
NameScores
Ana9588
Notes:

đź”— Additional Learning Resources

Practice Time!

Practice 1: Basic Table

Create a table showing your 3 favorite fruits, their color, and taste.

Practice 2: Weekly Schedule

Make a table with days of the week as headers and activities in each row.

Practice 3: Merge Cells

Create a pricing table where one cell spans across two columns or rows.