I'm doing an html table, with zebra striping. There's a small issue, that there's a visible non-colored space between colored cells. If I read correctly the browser inspector, it's a padding between cells of 1px. I don't manage to remove it.
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
To resolve the visible gap between table cells in your zebra-striped table, you need to eliminate the default spacing between cells. Here's the solution:
Step-by-Step Explanation & Code
Set border-collapse: collapse on the table
This merges adjacent cell borders and removes spacing between cells.
Apply background colors to table cells (<td>) instead of rows (<tr>)
This ensures the background covers the entire cell area without gaps.
Remove any conflicting styles
Ensure no border-spacing, padding, or margin is causing gaps.
This solution guarantees no gaps between zebra-striped cells. The combination of collapsed borders and cell-level backgrounds is reliable across all modern browsers.
User
yes, "border-collapse: collapse" did the trick. It's been decades I haven't done html, but that behavior and property don't ring any memory to me?
Assistant
You're not alone! The border-collapse property is one of those CSS features that many people forget about until they encounter spacing issues in tables. Let me explain why this behavior exists and why it might not be familiar:
The History of Table Spacing
HTML 3.2/Separate Borders Era (1997)
Early HTML tables used a "separate borders" model by default where:
Each cell had its own border
A 1-2px gap existed between cells
This spacing was intentional for readability in low-resolution displays
CSS2/Collapsing Borders (1998)
CSS introduced border-collapse to control this behavior:
yes, exactly, I used to deal with that using cellspacing, that's the memory I was after ><
Assistant
That makes perfect sense! The cellspacing attribute was the go-to solution in the early days of HTML table styling. Let's connect that memory to modern CSS:
td, th {
border: 1px solid #e0e0e0; /* Works perfectly with collapse */
padding: 12px; /* Now safe to use */
}
Why This Still Confuses People
Browser defaults:
Chrome/Firefox: border-spacing: 2px (in separate mode)
This tiny default spacing creates visible gaps
CSS resets:
css
/* Many modern resets include: */
table {
border-collapse: collapse;
border-spacing: 0;
}
(If you're using a CSS framework like Bootstrap, it's already handled)
Inheritance quirks:
The property only applies to <table> elements
Doesn't inherit to child elements
Pro Tip: Debugging Table Gaps
If you ever see gaps again, check for:
Missing border-collapse: collapse
Accidental border-spacing value
Backgrounds applied to <tr> instead of <td>
Transparent borders (use border: 1px solid transparent if needed)
This behavior has existed since CSS2, but many of us who took a long break from HTML/CSS find it's one of those hidden "gotchas" that's easy to forget! The web platform has kept this quirk for backward compatibility with old table layouts.
If you need space between cells with separate borders (like a grid of cards):
css
.card-grid {
border-collapse: separate; /* Default mode */
border-spacing: 8px; /* Like cellspacing but with pixels */
}
.card-grid td {
background: white;
border-radius: 8px; /* Works in separate mode */
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
The web has come full circle - what we did with attributes like cellspacing is now handled by CSS properties. border-collapse: collapse is essentially the professional, modern way to say "I want that cellspacing=0 look". The gap you saw was exactly what cellspacing="0" used to fix!