CSS Table Style - Explained with Examples

Elevate your tables with CSS Table Style! A comprehensive guide with examples for creative and visually appealing table designs, optimizing data presentation effortlessly.

Table Padding

To control the space between the border and the content in a table, use the padding property on <td> and <th> elements:

First NameLast NameSavings
PeterGriffin$100
LoisGriffin$150
JoeSwanson$300

Example

th, td {
  padding: 15px;
  text-align: left;
}

Horizontal Dividers

First NameLast NameSavings
PeterGriffin$100
LoisGriffin$150
JoeSwanson$300

Add the border-bottom property to <th> and <td> for horizontal dividers:

Example

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

Hoverable Table

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

First NameLast NameSavings
PeterGriffin$100
LoisGriffin$150
JoeSwanson$300

Example

tr:hover {background-color: coral;}

Striped Tables

First NameLast NameSavings
PeterGriffin$100
LoisGriffin$150
JoeSwanson$300

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

Example

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

Table Color

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

First NameLast NameSavings
PeterGriffin$100
LoisGriffin$150
JoeSwanson$300

Example

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

#css 

CSS Table Style - Explained with Examples
2.20 GEEK