HTML / HTML Tables

Using Table Headers and Footers

In this tutorial, we'll introduce you to table headers and footers in HTML. Headers provide labels for the columns, while footers can be used to summarize data or add additional i…

Tutorial 2 of 5 5 resources in this section

Section overview

5 resources

Covers the creation and styling of tables in HTML.

1. Introduction

Goal of the tutorial

This tutorial aims to equip you with the skills to use table headers and footers effectively in HTML. It will provide a clear understanding of how to use the <thead>, <th>, and <tfoot> elements.

What you will learn

  • The purpose of table headers and footers.
  • How to create table headers using the <thead> and <th> elements.
  • How to create table footers with the <tfoot> element.
  • Best practices for using these elements.

Prerequisites

Basic knowledge of HTML is required. Familiarity with HTML tables would be beneficial but not necessary as this tutorial will cover everything from the ground up.

2. Step-by-Step Guide

In HTML, tables are a way to present data in rows and columns. Headers (<thead> and <th>) provide labels for the columns, while footers (<tfoot>) can be used to summarize data or add additional information.

<thead> and <th>

The <thead> element is used to group the header content in an HTML table. The <th> element defines a header cell in a table. It makes the text bold and center-aligned by default.

<tfoot>

The <tfoot> element is used to group the footer content in an HTML table. It goes always after any <tbody> and <tr> elements, but before the <thead> and <tr> elements.

3. Code Examples

Example 1: Basic table with headers

<table>
    <thead>
        <tr>
            <th>Name</th>
            <th>Email</th>
            <th>Phone</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>John Doe</td>
            <td>john@example.com</td>
            <td>1234567890</td>
        </tr>
    </tbody>
</table>

In this example, the <thead> element is used to create a header row for the table. Each <th> element within the <thead> produces a header cell.

Example 2: Basic table with headers and footer

<table>
    <thead>
        <tr>
            <th>Name</th>
            <th>Email</th>
            <th>Phone</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>John Doe</td>
            <td>john@example.com</td>
            <td>1234567890</td>
        </tr>
    </tbody>
    <tfoot>
        <tr>
            <td colspan="3">Total Records: 1</td>
        </tr>
    </tfoot>
</table>

In this example, the <tfoot> element is used to create a footer row for the table. It summarizes the number of records in the table.

4. Summary

In this tutorial, you learned how to create table headers using the <thead> and <th> elements, and how to create a table footer with the <tfoot> element.

Continue practicing to get more familiar with these elements. Try to incorporate headers and footers in your future tables to make them more readable and structured.

For more information on HTML tables, check out the official HTML tables documentation.

5. Practice Exercises

Exercise 1: Basic table with headers

Create a table with headers for "Product", "Quantity", and "Price".

Exercise 2: Basic table with headers and footer

Add a footer to the table from Exercise 1, summarizing the "Total Price".

Solutions

  1. Here is the solution for Exercise 1.
<table>
    <thead>
        <tr>
            <th>Product</th>
            <th>Quantity</th>
            <th>Price</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>Apples</td>
            <td>5</td>
            <td>$5</td>
        </tr>
    </tbody>
</table>
  1. Here is the solution for Exercise 2.
<table>
    <thead>
        <tr>
            <th>Product</th>
            <th>Quantity</th>
            <th>Price</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>Apples</td>
            <td>5</td>
            <td>$5</td>
        </tr>
    </tbody>
    <tfoot>
        <tr>
            <td colspan="3">Total Price: $5</td>
        </tr>
    </tfoot>
</table>

Remember, practicing is key to mastering any concept. Keep trying different table structures to get a good grasp of these concepts.

Need Help Implementing This?

We build custom systems, plugins, and scalable infrastructure.

Discuss Your Project

Related topics

Keep learning with adjacent tracks.

View category

CSS

Master CSS to style and format web pages effectively.

Explore

JavaScript

Learn JavaScript to add interactivity and dynamic behavior to web pages.

Explore

Python

Explore Python for web development, data analysis, and automation.

Explore

SQL

Learn SQL to manage and query relational databases.

Explore

PHP

Master PHP to build dynamic and secure web applications.

Explore

Popular tools

Helpful utilities for quick tasks.

Browse tools

Lorem Ipsum Generator

Generate placeholder text for web design and mockups.

Use tool

Random String Generator

Generate random alphanumeric strings for API keys or unique IDs.

Use tool

JavaScript Minifier & Beautifier

Minify or beautify JavaScript code.

Use tool

Word Counter

Count words, characters, sentences, and paragraphs in real-time.

Use tool

PDF Compressor

Reduce the size of PDF files without losing quality.

Use tool

Latest articles

Fresh insights from the CodiWiki team.

Visit blog

AI in Drug Discovery: Accelerating Medical Breakthroughs

In the rapidly evolving landscape of healthcare and pharmaceuticals, Artificial Intelligence (AI) in drug dis…

Read article

AI in Retail: Personalized Shopping and Inventory Management

In the rapidly evolving retail landscape, the integration of Artificial Intelligence (AI) is revolutionizing …

Read article

AI in Public Safety: Predictive Policing and Crime Prevention

In the realm of public safety, the integration of Artificial Intelligence (AI) stands as a beacon of innovati…

Read article

AI in Mental Health: Assisting with Therapy and Diagnostics

In the realm of mental health, the integration of Artificial Intelligence (AI) stands as a beacon of hope and…

Read article

AI in Legal Compliance: Ensuring Regulatory Adherence

In an era where technology continually reshapes the boundaries of industries, Artificial Intelligence (AI) in…

Read article

Need help implementing this?

Get senior engineering support to ship it cleanly and on time.

Get Implementation Help