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.

<table> <tr> <td>Name</td> <td>Age</td> </tr> <tr> <td>Rahul</td> <td>20</td> </tr> </table>

This example creates a simple table with two rows and two columns.


Important Table Tags

table Tag

The tag defines the entire table structure.

<table>

It acts as the container for all table content.


Table Row Tag

The tag represents a table row.

<tr>

Each row contains data cells.


Table Data Tag

The tag represents individual data cells inside a row.

<td>Data</td>

Each forms a column entry.


Table Header Tag

The tag defines header cells. These appear bold and centered by default.

<th>Name</th>

Headers describe the content of columns.

Example with headers:

<table> <tr> <th>Name</th> <th>Marks</th> </tr> <tr> <td>Asha</td> <td>85</td> </tr> </table>

Additional Table Elements

Caption

Provides a title for the table.

<caption>Student Data</caption>

Table Sections

Used for better organization:

  • — header section

  • — body section

  • — footer section

Example:

<table> <thead> <tr><th>Item</th><th>Price</th></tr> </thead> <tbody> <tr><td>Book</td><td>200</td></tr> </tbody> </table>

Merging Cells

Tables allow combining cells.

Column merge:

<td colspan="2">Combined</td>

Row merge:

<td rowspan="2">Combined</td>

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.