SA-21/06, C-11, Asapur, Varanasi, UP support@kamaldnp.com +91 8318013442
CSS
1. CSS Tutorial for Beginners — Learn CSS from Scratch 2. CSS Syntax Explained — Selectors, Properties & Values 3. CSS Selectors Tutorial — Class, ID, Attribute & More 4. How to Add CSS to HTML — Inline, Internal, External 5. CSS Colors Tutorial — HEX, RGB, RGBA, HSL Explained 6. CSS Backgrounds Tutorial — Images, Size & Position 7. CSS Borders Tutorial — Style, Width, Radius & Shadow 8. CSS Margin Explained — Shorthand, Auto & Collapse 9. CSS Padding Explained — Shorthand & Margin Difference 10. CSS Height and Width — px, %, em, rem, vw, vh Units 11. CSS Box Model Explained — Content, Padding, Border 12. CSS Text Styling Tutorial — Color, Align & Spacing 13. CSS Fonts Tutorial — font-family, Sizes & Google Fonts 14. CSS Link Styling — Hover, Visited, Active & Buttons 15. CSS Lists Styling — Markers, Counters & Shorthand 16. CSS Tables Styling — Zebra Stripes & Hover Rows 17. CSS Display Property — Block, Inline, None Explained 18. CSS Position Explained — Relative, Absolute, Fixed 19. CSS Overflow Explained — Hidden, Scroll, Auto & More 20. CSS Float and Clear — Layouts & Clearfix Trick 21. CSS Pseudo-classes — Hover, Focus, nth-child & More 22. CSS Pseudo-elements — ::before, ::after & ::first-line 23. CSS Form Styling — Inputs, Labels & Buttons Tutorial 24. CSS Navigation Bar Tutorial — Dropdown Menu Included 25. CSS Website Layout Tutorial — Header, Sidebar, Footer 26. CSS Flexbox Tutorial — Complete Guide with Examples 27. CSS Grid Tutorial — Columns, Rows & Layouts Guide 28. CSS Responsive Design — Media Queries Tutorial 29. CSS Transitions & Animations — No JavaScript Needed 30. CSS Variables Tutorial — :root, var() & Theming 31. CSS Transforms Explained — Rotate, Scale, Translate 32. CSS Filters Tutorial — Blur, Grayscale, Sepia & More 33. CSS Text Effects — Shadows, Wrapping & Overflow 34. CSS Keyframes Tutorial — Bouncing Ball Animation 35. CSS Grid Template Areas — Layout in Words, Not Numbers
Final Test — Certificate ₹10
Try this code live
Lesson 16 of 35

CSS Tables Styling — Zebra Stripes & Hover Rows

4 min read · Free · No login needed

A plain HTML table works, but it looks bare — thin grey lines, cramped text, no colour at all. CSS turns that same table into a clean menu, a neat timetable, or a readable marksheet. You do not change the HTML. You only add style.

Diagram — see how it fits together
Diagram: CSS Tables

Tables are used everywhere: a chai shop menu, a school timetable, a cricket scorecard, an exam result list. If people must read rows of data, the table has to be easy on the eyes. That is the whole job of CSS tables.

Borders — the first step

Give the table, the headings and the cells a border with the border property. Without one more property, you get a strange result: every cell draws its own border, so you see double lines between cells. The fix is border-collapse: collapse on the table. It merges the touching borders into a single clean line.

table {
  border-collapse: collapse;
  width: 100%;
}
th, td {
  border: 1px solid #999;
  padding: 10px;
}

Width, padding and alignment

Three small properties do most of the work. width decides how wide the table is — 100% makes it fill its container. padding puts breathing space inside each cell, so the text does not touch the border. text-align lines the text up: headings and names on the left, numbers and prices on the right.

th, td {
  padding: 12px;
  text-align: left;
}
.price {
  text-align: right;
}

Zebra stripes — colour every second row

When a table has many rows, the eye slips to the wrong line. Zebra stripes fix that: give every even row a light background colour. The selector tr:nth-child(even) picks rows 2, 4, 6 and so on. You will meet :nth-child properly in the pseudo-classes lesson.

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

Hover rows

A hover row lights up the row under the mouse. It is a small touch, but it makes a long table much easier to read — the reader always knows which row they are on.

tr:hover {
  background-color: #ddd;
}

Responsive tables — small screens

A wide table breaks a phone screen: it either squeezes the text or pushes the page sideways. The simple fix is to wrap the table in a <div> with overflow-x: auto. On a small screen the table scrolls sideways inside its own box, and the rest of the page stays still.

<div style="overflow-x: auto;">
  <table> ... </table>
</div>
Note: border-collapse: collapse is the property beginners forget most. Without it, your table shows double borders — two thin lines with a tiny gap between them — and no amount of border styling will make it look right.
Tip: Style the heading row differently from the data rows — a dark background with white text, for example. Readers then spot the column names at a glance, even in a very long table.

Common mistakes

  • Forgetting border-collapse: collapse and wondering why the borders look doubled.
  • Putting a border only on the table and forgetting the cells — then only the outside edge shows.
  • Using <br> or extra spaces for spacing inside cells instead of padding.
  • Making the table a fixed pixel width, so it overflows on a phone screen.
  • Colouring every row the same dark shade, so the zebra stripes and the hover effect disappear.

Remember

  • border-collapse: collapse turns double borders into single clean lines.
  • padding gives the text room inside each cell; text-align lines it up.
  • tr:nth-child(even) makes zebra stripes; tr:hover lights up the row under the mouse.
  • Wrap a wide table in a div with overflow-x: auto so it scrolls on small screens.
  • Style the heading row (th) differently from the data rows (td).

Example explained

  • table { width: 80%; margin: 20px auto; border-collapse: collapse; } — the table takes 80% of the page width, sits in the centre, and its borders merge into single lines.
  • th, td { border: 1px solid #d97706; padding: 12px; text-align: left; } — every heading cell and data cell gets the same warm brown border, roomy padding, and left-aligned text.
  • th { background-color: #92400e; color: white; } — the heading row gets a dark brown background with white text, so the column names stand out.
  • tr:nth-child(even) { background-color: #fef3c7; } — every even row gets a pale yellow background, giving the menu its zebra stripes.
  • tr:hover { background-color: #fde68a; } — the row under the mouse turns a deeper yellow, so the reader never loses their place.
  • .price { text-align: right; } — the price column lines up on the right, which is how prices are normally read.

Example

Example
<!DOCTYPE html>
<html>
<head>
<title>Chai Shop Menu</title>
<style>
body {
  font-family: Arial, sans-serif;
  background-color: #fff8f0;
}
h1 {
  text-align: center;
  color: #7b3f00;
}
table {
  width: 80%;
  margin: 20px auto;
  border-collapse: collapse;
}
th, td {
  border: 1px solid #d97706;
  padding: 12px;
  text-align: left;
}
th {
  background-color: #92400e;
  color: white;
}
tr:nth-child(even) {
  background-color: #fef3c7;
}
tr:hover {
  background-color: #fde68a;
}
.price {
  text-align: right;
}
</style>
</head>
<body>

<h1>Chai &amp; Snacks — Menu</h1>
<div style="overflow-x: auto;">
<table>
<tr>
<th>Item</th>
<th>Size</th>
<th class="price">Price</th>
</tr>
<tr>
<td>Masala Chai</td>
<td>Small</td>
<td class="price">Rs 10</td>
</tr>
<tr>
<td>Masala Chai</td>
<td>Large</td>
<td class="price">Rs 15</td>
</tr>
<tr>
<td>Adrak Elaichi Chai</td>
<td>Large</td>
<td class="price">Rs 20</td>
</tr>
<tr>
<td>Samosa</td>
<td>1 pc</td>
<td class="price">Rs 10</td>
</tr>
<tr>
<td>Bread Pakora</td>
<td>2 pc</td>
<td class="price">Rs 20</td>
</tr>
<tr>
<td>Bun Maska</td>
<td>1 pc</td>
<td class="price">Rs 15</td>
</tr>
</table>
</div>
<p style="text-align: center;">Fresh chai served all day, 7 AM to 9 PM.</p>

</body>
</html>

Output

Output — how it looks in the browser
Output of CSS Tables Styling — Zebra Stripes & Hover Rows

Try it yourself — live editor

Change the code below and press Run to see the result instantly. No file to save, no login needed.

Result

Frequently asked questions

The questions learners ask most about this lesson — read the question, then open it to see the answer.

1. How do you fix doubled table borders?

With border-collapse: collapse. It turns double borders into single clean lines.

2. How do you make zebra stripes in a table?

With tr:nth-child(even), which colours every second row.

3. How do you make a wide table work on phones?

Wrap it in a div with overflow-x: auto, so it scrolls sideways on small screens.

Why learn this yourself — and not just ask AI?

AI can write code for you, but it cannot think for you. When you learn HTML yourself, your brain builds the real skill: you understand why a page looks the way it does, you can fix it when it breaks, and you can answer it in an exam or an interview without help. That is the skill that gets you a job — not a copied answer.

Get certified — just ₹10

Finish all 35 lessons, pass the test (80%), pay ₹10 and get your certificate.

Take the test

Prefer watching? Video courses teach the same topics step by step.

Go further with a full course

Free tutorials teach you the basics. Our paid courses add live projects, mentorship and a certificate.

Website Design Using WordPress 3 Days (Basic to Advanced)
₹199
View
Master Python + AI Skills in 30 Days
₹499
View
Android & iOS App Development using Flutter 2026
₹5,000
View
Browse all courses
CSS — Lessons
1. CSS Tutorial for Beginners — Learn CSS from Scratch 2. CSS Syntax Explained — Selectors, Properties & Values 3. CSS Selectors Tutorial — Class, ID, Attribute & More 4. How to Add CSS to HTML — Inline, Internal, External 5. CSS Colors Tutorial — HEX, RGB, RGBA, HSL Explained 6. CSS Backgrounds Tutorial — Images, Size & Position 7. CSS Borders Tutorial — Style, Width, Radius & Shadow 8. CSS Margin Explained — Shorthand, Auto & Collapse 9. CSS Padding Explained — Shorthand & Margin Difference 10. CSS Height and Width — px, %, em, rem, vw, vh Units 11. CSS Box Model Explained — Content, Padding, Border 12. CSS Text Styling Tutorial — Color, Align & Spacing 13. CSS Fonts Tutorial — font-family, Sizes & Google Fonts 14. CSS Link Styling — Hover, Visited, Active & Buttons 15. CSS Lists Styling — Markers, Counters & Shorthand 16. CSS Tables Styling — Zebra Stripes & Hover Rows 17. CSS Display Property — Block, Inline, None Explained 18. CSS Position Explained — Relative, Absolute, Fixed 19. CSS Overflow Explained — Hidden, Scroll, Auto & More 20. CSS Float and Clear — Layouts & Clearfix Trick 21. CSS Pseudo-classes — Hover, Focus, nth-child & More 22. CSS Pseudo-elements — ::before, ::after & ::first-line 23. CSS Form Styling — Inputs, Labels & Buttons Tutorial 24. CSS Navigation Bar Tutorial — Dropdown Menu Included 25. CSS Website Layout Tutorial — Header, Sidebar, Footer 26. CSS Flexbox Tutorial — Complete Guide with Examples 27. CSS Grid Tutorial — Columns, Rows & Layouts Guide 28. CSS Responsive Design — Media Queries Tutorial 29. CSS Transitions & Animations — No JavaScript Needed 30. CSS Variables Tutorial — :root, var() & Theming 31. CSS Transforms Explained — Rotate, Scale, Translate 32. CSS Filters Tutorial — Blur, Grayscale, Sepia & More 33. CSS Text Effects — Shadows, Wrapping & Overflow 34. CSS Keyframes Tutorial — Bouncing Ball Animation 35. CSS Grid Template Areas — Layout in Words, Not Numbers
Final Test — Certificate ₹10

🤖 KAMALDNP AI Assistant

Ask about courses, website & more

Hi! I'm KAMALDNP AI Assistant. Ask me about our courses, website features, or anything else! 😊
Please wait 5s...
🤖 KAMALDNP Assistant ✕

Request human callback:

🔐 Login Required
✕

Please log in to download. You will stay on this page after logging in!

New here? Register now →