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:
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
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:
Table text alignment
Text alignment and vertical alignment properties in tables.
The text-align property sets the horizontal alignment, left, right, or center:
The vertical alignment property sets vertical alignment, such as top, bottom, or middle:
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:
Table Colors
The following example specifies the color of the border, and the text and background color of the th elements:
Example
Try it Yourself »
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.