CSS · CSS Tutorial · Lesson 19
CSS Tables
Borders, collapse, striped and hoverable tables.
The look of an HTML table can be greatly improved with CSS.
Example
<style>
table { border-collapse: collapse; width: 100%; font-family: Arial, sans-serif; }
th, td { border-bottom: 1px solid #ddd; padding: 10px; text-align: left; }
th { background-color: #04AA6D; color: white; }
tr:nth-child(even) { background-color: #f2f2f2; }
tr:hover { background-color: #ddd; }
</style>
<table>
<tr><th>First name</th><th>Last name</th><th>Points</th></tr>
<tr><td>Peter</td><td>Griffin</td><td>$100</td></tr>
<tr><td>Lois</td><td>Griffin</td><td>$150</td></tr>
<tr><td>Joe</td><td>Swanson</td><td>$300</td></tr>
</table>
Tip: For responsive tables, wrap the table in a container with
overflow-x: auto.Keep reading “CSS Tables”
Sign up to read the full lesson, try every example in the live editor, and take the 5-question quiz.