Skip to main content

HTML Table Borders

By SamK
0
0 recommends
Topic(s)

You can assign borders to the HTML tables and cells.

Table borders can have various styles and shapes.

How To Add

To add a border, apply the CSS border property to <table>, <th>, and <td> elements.

table, th, td {
    border: 1px solid #000;
}

Table Border Demo

Collapsed Table Borders

You can easily notice in the above example that the simple border property is creating double borders. To prevent this effect, use the CSS border-collapse property, which merges the borders into a single border, as shown below.

table, th, td {
    border: 1px solid black;
    border-collapse: collapse;
}

Collapsed Table Border Demo

Invisible Borders

By setting a background color for each cell and making the border color white (matching the document background), you can create the illusion of an invisible border.

table, th, td {
    border: 1px solid white;
    border-collapse: collapse;
}
th, td {
    background-color: #ddd;
}

Invisible Border Demo

Rounded Borders

Using the border-radius property, borders can be given rounded corners.

table, th, td {
    border: 1px solid #000000;
    border-radius: 10px;
}

Round Table Borders Demo

You can omit the border around the table by excluding table from the CSS selector.

th, td {
    border: 1px solid black;
    border-radius: 10px;
}

Border Demo

Border Styles / Types

Using the border-style property, you can define the visual style of the border.

Possible values are:

dotted

td {
    border-style: solid;
}

Dotted Border Demo

dashed

td {
    border-style: dashed;
}

Dashed Border Demo

solid

td {
    border-style: solid;
}

Solid Border Demo

double

td {
    border-style: double;
}

Double Border Demo

groove

td {
    border-style: groove;
}

Groove Border Demo

ridge

td {
    border-style: ridge;
}

Ridge Border Demo

inset

td {
    border-style: inset;
}

Inset Border Demo

outset

td {
    border-style: outset;
}

Outset Border Demo

none

td {
    border-style: none;
}

hidden

td {
    border-style: hidden;
}

none is usually used to hide the borders from display.

Border Color

Using the border-color property, you can specify the color of the border.

th, td {
 border-color: #ff492c;
}

Border Color Demo