CSS Table Style
Table Padding
To control the space between the border and the content in a table, use the
padding property on
<td> and <th> elements:
Horizontal Dividers
| First Name | Last Name | Savings |
|---|---|---|
| Peter | Griffin | $100 |
| Lois | Griffin | $150 |
| Joe | Swanson | $300 |
Add the border-bottom property to <th> and <td> for horizontal dividers:
Hoverable Table
Use the :hover selector on <tr> to highlight table rows on mouse
over:
| First Name | Last Name | Savings |
|---|---|---|
| Peter | Griffin | $100 |
| Lois | Griffin | $150 |
| Joe | Swanson | $300 |
Striped Tables
| First Name | Last Name | Savings |
|---|---|---|
| Peter | Griffin | $100 |
| Lois | Griffin | $150 |
| Joe | Swanson | $300 |
For zebra-striped tables, use the nth-child() selector and add a background-color to all even (or odd) table rows:
Table Color
The example below specifies the background color and text color of <th> elements:
| First Name | Last Name | Savings |
|---|---|---|
| Peter | Griffin | $100 |
| Lois | Griffin | $150 |
| Joe | Swanson | $300 |
Example
th {
background: #11998e; /* fallback for old browsers */
background: -webkit-linear-gradient(to right, #38ef7d, #11998e); /* Chrome 10-25, Safari 5.1-6 */
background: linear-gradient(to right, #38ef7d, #11998e); /* W3C, IE 10+/ Edge, Firefox 16+, Chrome 26+, Opera 12+, Safari 7+ */
color: white;
}
Try it Yourself »