HOME C C++ PYTHON JAVA HTML CSS JAVASCRIPT BOOTSTRAP JQUERY REACT PHP SQL AJAX JSON DATA SCIENCE AI

Table Padding

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

Example

th, td {
  padding: 15px;
  text-align: left;
}
You can click on above box to edit the code and run again.

Output

Firstname Lastname Savings
Peter Griffin $100
Lois Griffin $150
Joe Swanson $300
Cleveland Brown $250

Horizontal Dividers

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

Example

th, td {
  border-bottom: 1px solid #ddd;
}
You can click on above box to edit the code and run again.

Output

Firstname Lastname Savings
Peter Griffin $100
Lois Griffin $150
Joe Swanson $300
Cleveland Brown $250

Hoverable Table

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

Example

tr:hover {background-color: coral;}
You can click on above box to edit the code and run again.

Output

Firstname Lastname Savings
Peter Griffin $100
Lois Griffin $150
Joe Swanson $300
Cleveland Brown $250

Striped Tables

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;}
You can click on above box to edit the code and run again.

Output

First Name Last Name Points
Peter Griffin $100
Lois Griffin $150
Joe Swanson $300
Cleveland Brown $250

Table Color

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

Example

tr:nth-child(even) {background-color: #f2f2f2;}
You can click on above box to edit the code and run again.

Output

First Name Last Name Points
Peter Griffin $100
Lois Griffin $150
Joe Swanson $300
Cleveland Brown $250