CSS Table


Using CSS can make HTML tables more beautiful.

Company Contact Country
Alfreds Futterkiste Maria Anders Germany
Berglunds snabbköp Christina Berglund Sweden
Centro comercial Moctezuma Francisco Chang Mexico
Ernst Handel Roland Mendel Austria
Island Trading Helen Bennett UK
Königlich Essen Philip Cramer Germany
Laughing Bacchus Winecellars Yoshi Tannamuri Canada
Magazzini Alimentari Riuniti Giovanni Rovelli Italy
North/South Simon Crowther UK
Paris spécialités Marie Bertrand France
The Big Cheese Liz Nixon USA
Vaffeljernet Palle Ibsen Denmark

Table Borders

To specify CSS table borders, use the border property.

The following example specifies a black border for the Th and TD elements of a table:

Example

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

Try it Yourself »

Note that the table in the example above has double borders. This is because the table and the th/td elements have separate borders.

To display a single border for a table, use the border-collapse property.

Collapse Borders

The border-collapse property sets whether the table borders are collapsed into a single border or separated:

Example

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

Try it Yourself »


Table width and height

The width and height properties define the width and height of a table.

The following example sets a table with 100% width and th elements with 50 pixels height:

Example

table { width:100%; } th { height:50px; }

Try it Yourself »


Table text alignment

Text alignment and vertical alignment properties in tables.

The text-align property sets the horizontal alignment, left, right, or center:

Example

td { text-align:right; }

Try it Yourself »

The vertical alignment property sets vertical alignment, such as top, bottom, or middle:

Example

td { height:50px; vertical-align:bottom; }

Try it Yourself »


Table Padding

To control the spacing between the border and the content of a table, use the padding property on the td and th elements:

Example

td { padding:15px; }

Try it Yourself »


Table Colors

The following example specifies the color of the border, and the text and background color of the th elements:

Example

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

Try it Yourself »


Examples

More Examples

Create a Personalized Table
This example demonstrates how to create a personalized table.

Set the Position of the Table Caption
This example demonstrates how to position a table caption.

other extensions