Text & Content Lesson 15 of 33
Styling Tables with CSS
Turn plain HTML tables into clean, readable data tables — borders, border-collapse, padding, zebra stripes, hover rows and mobile-friendly scrolling.
A plain HTML table works, but it can be hard to read: cramped cells, no lines, or old-fashioned double borders. With a few lines of CSS, you can turn it into a clean, professional table for grades, schedules or price lists.
We'll style this class schedule step by step:
<table>
<tr><th>Time</th><th>Monday</th><th>Tuesday</th><th>Wednesday</th></tr>
<tr><td>7:30–8:30</td><td>Math</td><td>English</td><td>Math</td></tr>
<tr><td>8:30–9:30</td><td>Science</td><td>Filipino</td><td>Science</td></tr>
<tr><td>9:30–9:45</td><td colspan="3">Recess</td></tr>
<tr><td>9:45–10:45</td><td>ICT</td><td>MAPEH</td><td>ICT</td></tr>
</table>
Step 1: Borders and border-collapse
If you add border: 1px solid to the table and the cells, you get double lines, because each cell has its own border with a gap between them. border-collapse: collapse merges them into single lines:
<style>
table { border-collapse: collapse; }
th, td { border: 1px solid #999; }
</style>
<table>
<tr><th>Time</th><th>Monday</th><th>Tuesday</th><th>Wednesday</th></tr>
<tr><td>7:30–8:30</td><td>Math</td><td>English</td><td>Math</td></tr>
<tr><td>8:30–9:30</td><td>Science</td><td>Filipino</td><td>Science</td></tr>
<tr><td>9:30–9:45</td><td colspan="3">Recess</td></tr>
<tr><td>9:45–10:45</td><td>ICT</td><td>MAPEH</td><td>ICT</td></tr>
</table>
Try removing border-collapse: collapse; to see the double lines come back.
Step 2: Padding and width
Cells need breathing room. Add padding, make the table full-width, and align the text:
<style>
table { border-collapse: collapse; width: 100%; font-family: Arial, sans-serif; }
th, td { border: 1px solid #ccc; padding: 10px 12px; text-align: left; }
</style>
<table>
<tr><th>Time</th><th>Monday</th><th>Tuesday</th><th>Wednesday</th></tr>
<tr><td>7:30–8:30</td><td>Math</td><td>English</td><td>Math</td></tr>
<tr><td>8:30–9:30</td><td>Science</td><td>Filipino</td><td>Science</td></tr>
<tr><td>9:30–9:45</td><td colspan="3">Recess</td></tr>
<tr><td>9:45–10:45</td><td>ICT</td><td>MAPEH</td><td>ICT</td></tr>
</table>
Step 3: Header color, zebra stripes and hover
Three finishing touches make tables much easier to read:
- A colored header row
- Zebra stripes — every other row slightly shaded, using
tr:nth-child(even) - A hover highlight, so the eye can follow a row across
<style>
table { border-collapse: collapse; width: 100%; font-family: Arial, sans-serif; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid #e3e0d6; }
th { background: #0f5c4d; color: white; }
tr:nth-child(even) td { background: #f3f6f4; }
tr:hover td { background: #fdf3dc; }
.break td { text-align: center; font-style: italic; color: #5b6662; }
</style>
<table>
<tr><th>Time</th><th>Monday</th><th>Tuesday</th><th>Wednesday</th></tr>
<tr><td>7:30–8:30</td><td>Math</td><td>English</td><td>Math</td></tr>
<tr><td>8:30–9:30</td><td>Science</td><td>Filipino</td><td>Science</td></tr>
<tr class="break"><td>9:30–9:45</td><td colspan="3">Recess</td></tr>
<tr><td>9:45–10:45</td><td>ICT</td><td>MAPEH</td><td>ICT</td></tr>
</table>
Notice we only used bottom borders this time. Modern tables often skip vertical lines completely. They look lighter and cleaner, and the stripes already guide the eye.
Aligning numbers
Numbers, especially money and grades, are easier to compare when they're right-aligned, so the ones, tens and hundreds line up. Give those cells a class:
<style>
table { border-collapse: collapse; font-family: Arial, sans-serif; min-width: 300px; }
th, td { padding: 8px 12px; border-bottom: 1px solid #ddd; text-align: left; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
tfoot td { font-weight: bold; border-top: 2px solid #333; }
</style>
<table>
<thead><tr><th>Item</th><th class="num">Sales (₱)</th></tr></thead>
<tbody>
<tr><td>Turon</td><td class="num">1,250.00</td></tr>
<tr><td>Banana cue</td><td class="num">980.50</td></tr>
<tr><td>Kwek-kwek</td><td class="num">2,115.00</td></tr>
</tbody>
<tfoot><tr><td>Total</td><td class="num">4,345.50</td></tr></tfoot>
</table>
font-variant-numeric: tabular-nums makes every digit the same width, so columns of numbers line up perfectly, even in fonts where "1" is narrower than "8".
Caption styling
A <caption> gives the table a title. You can style it and even move it under the table with caption-side: bottom;.
Tables on phones
Wide tables don't fit on narrow screens. The simplest reliable fix: wrap the table in a div that can scroll sideways.
<style>
.table-wrap { overflow-x: auto; border: 1px solid #ddd; border-radius: 8px; }
table { border-collapse: collapse; min-width: 600px; font-family: Arial, sans-serif; }
th, td { padding: 8px 12px; border-bottom: 1px solid #eee; text-align: left; white-space: nowrap; }
th { background: #f3f6f4; }
</style>
<div class="table-wrap">
<table>
<tr><th>Name</th><th>Q1</th><th>Q2</th><th>Q3</th><th>Q4</th><th>Final</th><th>Remarks</th></tr>
<tr><td>Dela Cruz, Juan</td><td>88</td><td>90</td><td>87</td><td>91</td><td>89</td><td>Passed</td></tr>
<tr><td>Santos, Maria</td><td>92</td><td>94</td><td>95</td><td>93</td><td>94</td><td>Passed</td></tr>
</table>
</div>
Only the table scrolls, not the whole page. Make the frame narrower (or view this on your phone) and swipe the table sideways.
Quick Quiz
Check what you learned. Walang grade ito, practice lang. 🙂
By Sir Reyel · Last updated 2026-12-04