HTML Tables Structure Headers & Accessibility
Introduction
HTML tables are one of the most useful ways to organize and display structured data on a webpage. If you have ever seen a school timetable, exam results list, price comparison chart, or sports ranking, you have already seen examples of HTML tables in action.
In web development, HTML tables allow developers to present data in rows and columns, making information easy to read and compare. This is especially useful when displaying data such as:
- Student marksheets
- Fee structures in PKR
- Product price lists
- Class schedules
- Cricket scoreboards
For Pakistani students learning web development, understanding HTML table structure is an essential skill. Many real-world websites in Pakistan — including schools, universities, government portals, and e-commerce platforms — rely on tables to display information clearly.
However, modern HTML tables are not just about rows and columns. Developers also need to understand:
- Proper table structure
- The use of
theadandtbody - Semantic HTML table tags
- Table accessibility for screen readers and assistive technologies
Learning these concepts will help you create clean, readable, and professional web pages that follow modern web standards.
In this tutorial, you will learn:
- How HTML tables work
- The structure of a table
- Important tags like
table,tr,th, andtd - The role of
theadandtbody - Best practices for table accessibility
- Real-world examples relevant to Pakistani students
By the end of this guide, you will be able to confidently create well-structured and accessible HTML tables.
Prerequisites
Before starting this tutorial, you should have basic knowledge of the following:
- Basic HTML page structure
- How to use HTML tags and elements
- Understanding of headings, paragraphs, and lists
- Basic familiarity with code editors like VS Code
If you are completely new to HTML, we recommend starting with:
- HTML Basics: Understanding Tags and Elements
- HTML Document Structure Explained
These tutorials are available on theiqra.edu.pk and will help you understand the fundamentals before working with tables.
Core Concepts & Explanation
Understanding HTML Table Structure
The structure of an HTML table is similar to a spreadsheet. It consists of:
- Rows
- Columns
- Cells
HTML tables use several important tags.
| Tag | Purpose |
|---|---|
<table> | Creates the table |
<tr> | Defines a table row |
<th> | Defines a table header cell |
<td> | Defines a table data cell |
Here is a simple table example.
<table>
<tr>
<th>Student Name</th>
<th>City</th>
<th>Marks</th>
</tr>
<tr>
<td>Ahmad</td>
<td>Lahore</td>
<td>85</td>
</tr>
<tr>
<td>Fatima</td>
<td>Karachi</td>
<td>92</td>
</tr>
</table>
Now let's understand each line.
Line-by-line explanation
<table>→ Starts the table container.<tr>→ Defines a row inside the table.<th>→ Creates header cells (usually bold and centered).<td>→ Creates regular data cells.- Each row represents one record.
This table displays student marks, which is a common real-world example for Pakistani students.
Using thead and tbody for Better Structure
As tables become larger, it becomes important to organize them properly. This is where thead and tbody come in.
These tags help separate header rows from the main table content.
| Tag | Purpose |
|---|---|
<thead> | Groups the table header |
<tbody> | Groups the table body |
Example:
<table>
<thead>
<tr>
<th>Student</th>
<th>City</th>
<th>Marks</th>
</tr>
</thead>
<tbody>
<tr>
<td>Ali</td>
<td>Islamabad</td>
<td>88</td>
</tr>
<tr>
<td>Fatima</td>
<td>Lahore</td>
<td>91</td>
</tr>
</tbody>
</table>
Explanation
<thead>groups the column headings.<tbody>contains the actual data rows.- This structure improves readability, styling, and accessibility.
Browsers and screen readers use this structure to understand the meaning of table data.

HTML Table Tags and Their Roles
HTML tables rely on several tags that work together.
<table>
This is the main container for the entire table.
<tr>
Represents a table row.
Each row contains cells.
<th>
Represents header cells.
These are usually used in the first row.
<td>
Represents data cells containing actual information.
Example showing structure clearly:
<table>
<tr>
<th>Course</th>
<th>Fee (PKR)</th>
</tr>
<tr>
<td>Web Development</td>
<td>15000</td>
</tr>
</table>
This example shows a course fee table for a training institute.
Table Accessibility
Accessibility ensures that all users, including those using screen readers, can understand your tables.
Some best practices include:
- Use
<th>for headers - Organize tables with
theadandtbody - Provide clear labels
- Avoid using tables purely for layout
Example with better accessibility:
<table>
<thead>
<tr>
<th scope="col">Student</th>
<th scope="col">Subject</th>
<th scope="col">Marks</th>
</tr>
</thead>
<tbody>
<tr>
<td>Ahmad</td>
<td>Mathematics</td>
<td>89</td>
</tr>
</tbody>
</table>
Explanation
scope="col"tells screen readers that this header relates to a column.- This helps visually impaired users navigate tables more easily.
Accessibility is an important skill for modern web developers.
Practical Code Examples
Example 1: Student Marks Table
Let's build a simple student marks table.
<table border="1">
<thead>
<tr>
<th>Student Name</th>
<th>Subject</th>
<th>Marks</th>
</tr>
</thead>
<tbody>
<tr>
<td>Ali</td>
<td>Computer Science</td>
<td>90</td>
</tr>
<tr>
<td>Fatima</td>
<td>Mathematics</td>
<td>87</td>
</tr>
</tbody>
</table>
Line-by-line explanation
<table border="1">→ Creates the table with visible borders.<thead>→ Groups the header row.<th>→ Defines column headings.<tbody>→ Contains the main data.<td>→ Displays actual student data.
This table shows student marks in different subjects.
Example 2: Real-World Application (Course Fee Table)
Many educational websites show course fee structures using tables.
<table border="1">
<thead>
<tr>
<th>Course Name</th>
<th>Duration</th>
<th>Fee (PKR)</th>
</tr>
</thead>
<tbody>
<tr>
<td>Web Development</td>
<td>3 Months</td>
<td>15000</td>
</tr>
<tr>
<td>Graphic Design</td>
<td>2 Months</td>
<td>12000</td>
</tr>
</tbody>
</table>
Explanation
- First row contains column headers.
- Each row shows details about a course.
- Data is organized clearly for users.
This is similar to how training institutes in Lahore or Karachi display fee structures.

Common Mistakes & How to Avoid Them
Mistake 1: Forgetting <tr> Tags
Some beginners forget to wrap cells inside rows.
Incorrect example:
<table>
<td>Ali</td>
<td>90</td>
</table>
Correct version:
<table>
<tr>
<td>Ali</td>
<td>90</td>
</tr>
</table>
Always remember:
Cells must be inside rows.
Mistake 2: Using Tables for Page Layout
Older websites used tables to create page layouts.
Example of bad practice:
<table>
<tr>
<td>Sidebar</td>
<td>Main Content</td>
</tr>
</table>
Today we use CSS Flexbox or Grid instead.
Tables should only be used for data representation, not layout.
Practice Exercises
Exercise 1: Create a Student Table
Task
Create a table with the following columns:
- Student Name
- City
- Age
Add two students.
Solution
<table border="1">
<tr>
<th>Student Name</th>
<th>City</th>
<th>Age</th>
</tr>
<tr>
<td>Ahmad</td>
<td>Lahore</td>
<td>20</td>
</tr>
<tr>
<td>Fatima</td>
<td>Karachi</td>
<td>19</td>
</tr>
</table>
Exercise 2: Course Fee Table
Task
Create a table showing:
- Course Name
- Duration
- Fee
Solution
<table border="1">
<tr>
<th>Course</th>
<th>Duration</th>
<th>Fee (PKR)</th>
</tr>
<tr>
<td>HTML & CSS</td>
<td>1 Month</td>
<td>8000</td>
</tr>
<tr>
<td>JavaScript</td>
<td>2 Months</td>
<td>12000</td>
</tr>
</table>
Frequently Asked Questions
What is an HTML table?
An HTML table is used to display data in rows and columns. It helps organize information like schedules, price lists, and student records in a clear format.
How do I create a table in HTML?
You create a table using the <table> tag. Inside it, you define rows with <tr> and cells with <td> or <th>.
What is the difference between <th> and <td>?
<th> represents a header cell, usually used for column titles. <td> represents regular data cells that contain the table's actual information.
Why are thead and tbody important?
They organize tables into header and body sections. This improves readability, styling, and accessibility for screen readers.
How can I make HTML tables accessible?
Use semantic tags like <th>, include scope attributes, and structure the table using thead and tbody. This helps assistive technologies understand the table correctly.
Summary & Key Takeaways
- HTML tables display structured data in rows and columns.
- Important tags include
table,tr,th, andtd. - Use
theadandtbodyto organize table structure. - Proper table structure improves readability and accessibility.
- Tables should be used for data, not page layout.
- Accessibility features help screen readers interpret table data.
Next Steps & Related Tutorials
Now that you understand HTML tables, you can continue learning more HTML concepts.
Recommended tutorials on theiqra.edu.pk:
- Learn HTML Lists for Organizing Content
- Understand HTML Forms and Input Fields
- Explore HTML Semantic Elements Explained
- Start styling tables with CSS Basics for Beginners
These tutorials will help you move from basic HTML structure to building complete websites.
Test Your Python Knowledge!
Finished reading? Take a quick quiz to see how much you've learned from this tutorial.