Skip to main content

HTML Table Borders

HTML tables can have borders of different styles and shapes.


How To Add a Border

To add a border, use the CSS border property on the table, th, and td elements.

Example

A table with a black border on the table and cells.

Prompt
A table styled with CSS so the table, th and td each have a 1px solid black border, with a sample company table.
Output: complete HTML page

Collapsed Table Borders

To avoid double borders, set the CSS border-collapse property to collapse. This merges the borders into a single line.

Example

A table with collapsed, single-line borders.

Prompt
A table with 1px solid black borders and border-collapse set to collapse, so the double borders merge into single lines.
Output: complete HTML page

Style Table Borders

If you give each cell a background color and make the border the same color as the page background, the borders look invisible.

Example

Cells with a colored background and matching white borders.

Prompt
A table where the borders are white (matching the page background) and each cell has a colored background (#96D4D4), giving the look of invisible borders. Use border-collapse collapse.
Output: complete HTML page

Round Table Borders

The border-radius property gives the borders rounded corners. Leave table out of the selector to skip the border around the whole table.

Rounded table and cells

Rounded corners on the table and the cells.

Prompt
A table with 1px solid black borders and rounded corners using border-radius 10px on table, th and td.
Output: complete HTML page

Rounded cells only

Rounded corners on the cells only, with no outer table border.

Prompt
A table where only the cells (th and td) have rounded 1px black borders, leaving out the table element so the outer table border is skipped.
Output: complete HTML page

Dotted Table Borders

The border-style property sets how the border looks. Allowed values are: dotted, dashed, solid, double, groove, ridge, inset, outset, none, and hidden.

Example

Cells with a dotted border.

Prompt
A table whose cells use a dotted border via the border-style property set to dotted on th and td.
Output: complete HTML page

Border Color

The border-color property sets the color of the border.

Example

Cells with colored borders.

Prompt
A table whose cell borders are colored #96D4D4 using the border-color property on th and td.
Output: complete HTML page