Defining Tables in HTML

An HTML table is defined with the “table” tag. Each table row is defined with the “tr” tag. A table header is defined with the “th” tag. By default, table headings are bold and centered. A table data/cell is defined with the “td” tag.

Table Cells

Table Cell are the building blocks for defining the Table. It is denoted with <td> as a start tag & </td> as a end tag.

Syntax

</td> Content...</td> 

Table Rows

The rows can be formed with the help of combination of Table Cells. It is denoted by <tr> and </tr> tag as a start & end tags.

Syntax

</tr> Content...</tr> 

Table Headers

The Headers are generally use to provide the Heading. The Table Headers can also be used to add the heading to the Table. This contains the <th> & </th> tags.

Syntax

</th> Content...</th> 

Example 1: Creating a simple table in HTML using a table tag. 

HTML
<!-- index.html -->
<!DOCTYPE html>
<html>

<body>
    <table>
        <tr>
            <th>Book Name</th>
            <th>Author Name</th>
            <th>Genre</th>
        </tr>
        <tr>
            <td>The Book Thief</td>
            <td>Markus Zusak</td>
            <td>Historical Fiction</td>
        </tr>
        <tr>
            <td>The Cruel Prince</td>
            <td>Holly Black</td>
            <td>Fantasy</td>
        </tr>
        <tr>
            <td>The Silent Patient</td>
            <td> Alex Michaelides</td>
            <td>Psychological Fiction</td>
        </tr>
    </table>
</body>

</html>

Output:

HTML Table

HTML Tables

HTML tables offer a powerful tool for presenting data on your website. But mastering them goes beyond just rows and columns. This article serves as your ultimate guide to unlocking the potential of HTML tables, stepping beyond the basics.

Prerequisites: HTML Introduction

Similar Reads

What is HTML Tables?

...

HTML Table Code Example

An HTML Table is an arrangement of data in rows and columns in tabular format. Tables are useful for various tasks, such as presenting text information and numerical data. A table is a useful tool for quickly and easily finding connections between different types of data. Tables are also used to create databases....

Tags used in HTML Tables

HTML

Firstname Lastname Age
Priya Sharma 24
Arun Singh 32
Sam Watson 41
...

Defining Tables in HTML

HTML Tags Descriptions

Defines the structure for organizing data in rows and columns within a web page.Represents a row within an HTML table, containing individual cells.Defines the header section of a table, often containing column labels.Represents the main content area of a table, separating it from the header or footer.Specifies the footer section of a table, typically holding summaries or totals.Defines attributes for table columns that can be applied to multiple columns at once.Groups together a set of columns in a table to which you can apply formatting or properties collectively....

Adding a border to an HTML Table

An HTML table is defined with the “table” tag. Each table row is defined with the “tr” tag. A table header is defined with the “th” tag. By default, table headings are bold and centered. A table data/cell is defined with the “td” tag....

Adding Collapsed Borders in an HTML Table

A border is set using the CSS border property. If you do not specify a border for the table, it will be displayed without borders....

Adding Cell Padding in an HTML Table

For borders to collapse into one border, add the CSS border-collapse property....

Adding Left Align Headings in an HTML Table

Cell padding specifies the space between the cell content and its borders. If we do not specify a padding, the table cells will be displayed without padding....

Adding Border Spacing in an HTML Table

By default, the table headings are bold and centered. To left-align the table headings, we must use the CSS text-align property....

Adding Cells that Span Many Columns in HTML Tables

Border spacing specifies the space between the cells. To set the border-spacing for a table, we must use the CSS border-spacing property....

Adding Cells that span many rows in HTML Tables

To make a cell span more than one column, we must use the colspan attribute....

Adding a Caption in an HTML Table

To make a cell span more than one row, we must use the rowspan attribute....

Adding a Background Colour to the Table

To add a caption to a table, we must use the “caption” tag....

Creating Nested Tables

A color can be added as a background in an HTML table using the “background-color” option....

Supported Browsers

Nesting tables simply means making a Table inside another Table. Nesting tables can lead to complex tables layouts, which are visually interesting and have the potential of introducing errors....

Contact Us

Shows a table header cell that typically holds titles or headings.Represents a standard data cell, holding content or data.
Provides a title or description for the entire table.