Adding Border Spacing in an HTML Table

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

Syntax

table {
border-spacing: 5px;
}

Example: Explains the border space property to make the space between the Table cells.

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

<head>
    <style>
        table,
        th,
        td {
            border: 1px solid black;
        }

        table {
            border-spacing: 5px;
        }
    </style>
</head>

<body>
    <table style="width:100%">
        <tr>
            <th>Firstname</th>
            <th>Lastname</th>
            <th>Age</th>
        </tr>
        <tr>
            <td>Priya</td>
            <td>Sharma</td>
            <td>24</td>
        </tr>
        <tr>
            <td>Arun</td>
            <td>Singh</td>
            <td>32</td>
        </tr>
        <tr>
            <td>Sam</td>
            <td>Watson</td>
            <td>41</td>
        </tr>
    </table>
</body>

</html>

Output:

Border Spacing Property

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.