bugl
bugl
HomeLearnPatternsPathsSearchPremium
HomeLearnPatternsPaths

Loading lesson path

Learn/CSS/CSS Foundations
CSS•CSS Foundations

CSS Table Styling

CSS Table Padding

To add some more space between the inner borders and the content in a table, use the padding property on <td> and <th> elements:

First NameLast NameSavings

Example

Formatted code
th, td {
  padding: 10px;
  text-align: left;
}

Live preview

CSS Horizontal Dividers

To create horizontal dividers for a table, add the border-bottom property to <th> and <td> elements:

First NameLast NameSavings

Example

Formatted code
th, td {
  border-bottom: 1px solid #ddd;
}

Live preview

CSS Hoverable Table

Use the CSS :hover selector on <tr> to highlight table rows on mouse over:

First NameLast NameSavings

Example

Formatted code
tr:hover {background-color: coral;}

Live preview

CSS Zebra-striped Table

For zebra-striped tables, use the nth-child() selector and add a background-color to all even (or odd) table rows:

First NameLast NameSavings

Example

Formatted code
tr:nth-child(even) {background-color: #f2f2f2;}

Live preview

CSS Table Color

The example below specifies a background color and a text color for the <th> elements:

First NameLast NameSavings

Example

Formatted code
th {
  background-color: #04AA6D;
  color: white;
}

Live preview

Previous

CSS Table Alignment

Next

CSS Responsive Tables