HTML - Tables in HTML
Introduction
Tables in HTML are used to display data in a structured format using rows and columns. They are helpful when presenting information such as schedules, reports, statistics, or comparison data. HTML tables organize content so that users can easily read and interpret related information.
Basic Structure of a Table
An HTML table is created using several tags that define its layout.
This example creates a simple table with two rows and two columns.
Important Table Tags
table Tag
The tag defines the entire table structure.
It acts as the container for all table content.
Table Row Tag
The tag represents a table row.
Each row contains data cells.
Table Data Tag
The tag represents individual data cells inside a row.
Each forms a column entry.
Table Header Tag
The tag defines header cells. These appear bold and centered by default.
Headers describe the content of columns.
Example with headers:
Additional Table Elements
Caption
Provides a title for the table.
Table Sections
Used for better organization:
-
— header section
-
— body section
-
— footer section
Example:
Merging Cells
Tables allow combining cells.
Column merge:
Row merge:
These attributes improve layout flexibility.
Importance of Tables
Using tables correctly:
-
Organizes complex data clearly
-
Improves readability
-
Helps comparison of information
-
Supports structured presentation
-
Useful in academic and business reports
Tables should be used for data presentation, not page layout.
Summary
HTML tables provide a structured way to display information in rows and columns using tags such as table, tr, th, and td. Additional features like captions, sections, and cell merging enhance organization and readability. Mastering tables helps students present data effectively in webpages.