PP HTML Tables Lesson

HTML 0 to Infinity Lesson

Learn Tables in HTML by Building Real Data Tables

In this lesson, we will learn HTML tables from the first idea to practical use. We will build student marks tables, timetable tables, product comparison tables, and responsive tables that look good on mobile screens.

table tr th td caption colspan + rowspan Responsive Tables

Lesson Goal

A table is used when information belongs naturally in rows and columns.

Main idea

  • Use tables for real tabular data.
  • Do not use tables only to design page layout.
  • Use headings so readers understand each column.
  • Use semantic tags so browsers, screen readers, and search engines understand the table better.

Simple test

Ask: “Can this content be understood as rows and columns?” If yes, a table may be the right element.

0

Level 0 — Understand the table family

First understand the main tags.

HTML tables are built like a grid. The <table> is the outer box. Each <tr> creates a row. Inside rows, <th> creates a heading cell and <td> creates a normal data cell.
Table tag map
<table>
whole table
<tr>
table row
<th>
heading cell
<td>
data cell
Smallest useful table
<table>
  <tr>
    <th>Name</th>
    <th>Course</th>
  </tr>
  <tr>
    <td>Aarav</td>
    <td>HTML</td>
  </tr>
</table>
1

Level 1 — Build a marks table

Rows and columns become meaningful data.

In a marks table, each row represents one student. Each column represents one property: name, HTML score, CSS score, and result. This is exactly what a table is made for.
Preview: student marks table
StudentHTMLCSSResult
Aarav9288Pass
Meera8491Pass
Kabir7166Pass
Marks table HTML
<table>
  <tr>
    <th>Student</th>
    <th>HTML</th>
    <th>CSS</th>
    <th>Result</th>
  </tr>
  <tr>
    <td>Aarav</td>
    <td>92</td>
    <td>88</td>
    <td>Pass</td>
  </tr>
  <tr>
    <td>Meera</td>
    <td>84</td>
    <td>91</td>
    <td>Pass</td>
  </tr>
</table>
2

Level 2 — Add caption, thead, tbody, and tfoot

Now make the table more meaningful.

A good table is not only visible; it is understandable. Use caption for the table title, thead for header rows, tbody for main data, and tfoot for totals or summary rows.

Useful table parts

  • caption: table title
  • thead: heading section
  • tbody: data section
  • tfoot: summary section

Why this matters

These tags help structure the table clearly. They also make styling and accessibility easier.

Preview: semantic table
Course Progress Report
TopicClassesStatus
HTML Basics3Completed
HTML Tables2Running
Total Topics2
Semantic table HTML
<table>
  <caption>Course Progress Report</caption>

  <thead>
    <tr>
      <th>Topic</th>
      <th>Classes</th>
      <th>Status</th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td>HTML Basics</td>
      <td>3</td>
      <td>Completed</td>
    </tr>
    <tr>
      <td>HTML Tables</td>
      <td>2</td>
      <td>Running</td>
    </tr>
  </tbody>

  <tfoot>
    <tr>
      <td colspan="2">Total Topics</td>
      <td>2</td>
    </tr>
  </tfoot>
</table>
3

Level 3 — Merge cells using colspan and rowspan

Some tables need cells that cover more space.

Use colspan when one cell should stretch across multiple columns. Use rowspan when one cell should stretch across multiple rows.
Visual idea of merging
colspan="2"
Cell
Cell
rowspan="2"
Cell
Cell
Cell
Cell
Preview: weekly timetable
Weekly Coding Timetable
DayTimeTopic
Monday11:00 AMHTML Table Basics
12:00 PMPractice Questions
SundayTest, revision, doubt solving, and mini project
colspan and rowspan example
<table>
  <caption>Weekly Coding Timetable</caption>
  <tr>
    <th>Day</th>
    <th>Time</th>
    <th>Topic</th>
  </tr>
  <tr>
    <td rowspan="2">Monday</td>
    <td>11:00 AM</td>
    <td>HTML Table Basics</td>
  </tr>
  <tr>
    <td>12:00 PM</td>
    <td>Practice Questions</td>
  </tr>
  <tr>
    <td>Sunday</td>
    <td colspan="2">Test, revision, doubt solving, and mini project</td>
  </tr>
</table>
4

Level 4 — Style and make tables responsive

A table must be readable on desktop and mobile.

Good table styling uses readable spacing, clear borders, strong heading colors, and enough contrast. For small screens, wrap the table inside a scroll container so the page does not break.
Final responsive product comparison table
HTML Course Package Comparison
PlanBest ForIncludesSupport
StarterBeginnersHTML basics, tags, links, imagesEmail
BuilderProject learnersTables, forms, layout, mini projectsWhatsApp guidance
MasterySerious studentsHTML, CSS, JavaScript, deploymentWhatsApp + Zoom
Choose the plan according to your current confidence and practice time.

Good styling

  • Use border-collapse: collapse.
  • Add enough padding.
  • Make th visually different.
  • Use zebra rows when many rows are present.

Responsive rule

Put the table inside a wrapper with overflow-x:auto. This allows horizontal scrolling on small screens.

Final responsive table code
<div class="table-wrapper">
  <table class="course-table">
    <caption>HTML Course Package Comparison</caption>
    <thead>
      <tr>
        <th>Plan</th>
        <th>Best For</th>
        <th>Includes</th>
        <th>Support</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td>Starter</td>
        <td>Beginners</td>
        <td>HTML basics, tags, links, images</td>
        <td>Email</td>
      </tr>
      <tr>
        <td>Builder</td>
        <td>Project learners</td>
        <td>Tables, forms, layout, mini projects</td>
        <td>WhatsApp guidance</td>
      </tr>
    </tbody>
  </table>
</div>

<style>
.table-wrapper{
  overflow-x:auto;
  border:1px solid #efdfb2;
  border-radius:16px;
}

.course-table{
  width:100%;
  min-width:620px;
  border-collapse:collapse;
}

.course-table caption{
  text-align:left;
  font-weight:900;
  padding:12px 14px;
  background:#fff7ea;
}

.course-table th,
.course-table td{
  border:1px solid #efdfb2;
  padding:12px 14px;
  text-align:left;
}

.course-table th{
  background:#fff4d6;
}

.course-table tbody tr:nth-child(even){
  background:#fffaf0;
}
</style>
5

Level 5 — Table accessibility and mistakes to avoid

Readable for humans, meaningful for assistive tools.

Avoid

  • Using tables to create page layout.
  • Leaving table headings empty.
  • Making very wide tables without a scroll wrapper.
  • Using tiny text or low-contrast colors.

Prefer

  • Use caption for the table purpose.
  • Use th for headings.
  • Use scope="col" or scope="row" where useful.
  • Keep data consistent in every row.
Accessible heading scope example
<table>
  <caption>Monthly Attendance</caption>
  <tr>
    <th scope="col">Student</th>
    <th scope="col">Present Days</th>
    <th scope="col">Absent Days</th>
  </tr>
  <tr>
    <th scope="row">Aarav</th>
    <td>24</td>
    <td>2</td>
  </tr>
</table>

Practice Challenge

Try building these tables yourself.

Challenge 1: Make a 5-row student marks table with columns: Name, HTML, CSS, JavaScript, Total.
Show idea

Use one header row with th, then five data rows with td.

Challenge 2: Create a weekly class timetable and use rowspan for a day that has two classes.
Show idea

Put rowspan="2" on the day cell and create two time/topic rows.

Challenge 3: Create a product comparison table with a responsive wrapper.
Show idea

Wrap the table in <div class="table-wrapper"> and set overflow-x:auto.

Final Summary

You learned how to create tables that are structured, readable, styled, and mobile-friendly.

What you learned

  1. table creates the table.
  2. tr creates a row.
  3. th creates a heading cell.
  4. td creates a data cell.
  5. caption, thead, tbody, and tfoot make the table semantic.
  6. colspan and rowspan merge cells.
  7. A scroll wrapper keeps wide tables usable on mobile.

Best next step

Build a real course timetable, a fee structure table, and a student result table. Tables become easy only when you create them repeatedly.