Advanced Table Features

HTML tables are not only used for displaying data; they are also used to organize information in a structured, meaningful, and readable way.

To make tables professional, accessible, and easy to understand, we use advanced features.

Table Sections: <thead>, <tbody>, <tfoot>

These tags divide the table into three logical sections.

<thead> - (Table Head)

<thead>
    <tr>
        <th>Subject</th>
        <th>Marks</th>
    </tr>
</thead>

<tbody> - (Table Body)

<tbody>
    <tr>
        <td>Maths</td>
        <td>85</td>
    </tr>
</tbody>

<tfoot> - (Table Footer)

<tfoot>
    <tr>
        <td>Total</td>
        <td>80</td>
    </tr>
</tfoot>
                

Even if <tfoot> is written before <tbody>, it is still displayed at the bottom of the table. This shows that semantic structure is prioritized over the order in the code.

Colspan and Rowspan (Merging Cells)

These attributes are used when we need a cell to span across multiple rows or columns.

colspan - (Column Span)

This attribute allows a cell to span across multiple columns.

Features:

Why do we use it?

Example:

<td colspan="3">Total Marks</td>

This means:

This single cell will take up the space of 3 columns.

rowspan - (Row Span)

This attribute allows a cell to span across multiple rows in a table.

Features:

Why do we use it?

Example:

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

This cell will span across 2 rows vertically.

Table Accessibility

Table accessibility means making your table usable for all users:

Best practices explained:

Semantic Tables

Using HTML tags based on their meaning helps ensure that the correct tags are used.

Non-Semantic Table

<table>
    <tr>
        <td>Subject</td>
        <td>Marks</td>
    </tr>
</table>

Problem:

Semantic Table

<table border="1">
    <caption>Student Marks</caption>
    <thead>
        <tr>
            <th scope="col">Subject</th>
            <th scope="col">Marks</th>
        </tr>
    </thead>          

    <tbody>
        <tr>
            <td>English</td>
            <td>92</td>
        </tr>
    </tbody>
</table>

Benefits of Semantic Tables

Conclusion

Advanced table features are not just about presenting data; they are about displaying content in a clear, structured, and meaningful way.

A well-designed table helps users understand data more easily by: