Styling Tables
Style tables with CSS rather than the old border attribute. border-collapse: collapse merges neighbouring borders, and padding gives cells breathing room.
The :nth-child(even) selector creates striped rows that are easier to read.
Example
<style>
table { border-collapse: collapse; width: 100%; }
th, td { border: 1px solid #cbd5e1; padding: 8px; text-align: left; }
th { background: #166534; color: white; }
tr:nth-child(even) td { background: #f1f5f9; }
</style>
<table>
<tr><th>Course</th><th>Lessons</th></tr>
<tr><td>HTML</td><td>50</td></tr>
<tr><td>CSS</td><td>59</td></tr>
<tr><td>Python</td><td>70</td></tr>
</table>Exercise
Merge the cell borders.
table { border-: collapse; }
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.