How to use the CSS Table Styler
- 1
Colour the header
Choose header background and text colours — the header row is what people scan first.
- 2
Set borders and stripes
Pick borders between rows, around all cells, or none; toggle zebra stripes and row hover.
- 3
Tune spacing
Adjust cell padding (4–24px), corner radius (0–20px) and font size (12–20px).
- 4
Copy the CSS
Add class="styled-table" to your <table> and paste the rules.
Features
Proportional padding
Horizontal padding is 1.3× the vertical value, so 12px becomes 12px 16px.
Zebra striping
Colours every even body row with tbody tr:nth-child(even).
Auto hover colour
Row hover uses your header colour mixed 86% toward white, so it always matches.
Number alignment
Right-align every column except the first, so figures line up by place value.
Rounded tables
Uses separate borders with zero spacing and overflow: hidden so corners actually round.
Clean edges
Removes the doubled bottom border on the last row and the right border on the last column.
Who uses it — and for what
Pricing pages
Compare plans, limits and prices in a clear grid.
Documentation
Style API parameter and option tables consistently.
Admin dashboards
Make order, invoice and user lists easier to scan.
Blogs
Present comparisons and specs in articles.
Readable tables
Tables are for comparing data, so the styling should help eyes travel along rows. Zebra stripes or light row borders guide the eye across wide tables; a contrasting header makes columns easy to identify; generous padding stops numbers running together; and right-aligning numeric columns lines up the digits for easy comparison. Hover highlighting helps on desktop when people scan long rows.
Rounded corners and mobile
Tables ignore border-radius while border-collapse: collapse is on, so the generated CSS uses border-collapse: separate; border-spacing: 0 with overflow: hidden to round the corners. On small screens, wrap the table in a container with overflow-x: auto so it scrolls sideways instead of breaking the page. Keep real <th> header cells — screen readers use them to announce each value with its column name.
Everything updates live as you drag — copy the code when it looks right. Nothing is uploaded and there is no sign-up.
Markup that makes the CSS work
The generated selectors expect a properly structured table. They target thead th for the header and tbody tr for stripes and hover, so a table with no <thead> and <tbody> will lose those styles. A minimal, accessible structure looks like this:
<table class="styled-table">
<caption>Plans and limits</caption>
<thead>
<tr><th scope="col">Plan</th><th scope="col">Price</th></tr>
</thead>
<tbody>
<tr><th scope="row">Starter</th><td>$0</td></tr>
</tbody>
</table>
- <caption> gives the table a name that screen readers announce. Style or visually hide it if it doesn’t fit your design.
- scope="col" and scope="row" tell assistive technology which header belongs to each cell.
- Row headers (
thinsidetbody) pick up the padding and border rules from the generatedth, tdselector but not the coloured header background, which only applies insidethead.
Browsers insert a tbody automatically if you leave it out, but writing it explicitly avoids surprises with JavaScript and CSS.
Common extensions and one trap
Once the base styles are in place, a few small additions make data tables much nicer:
- Tabular figures: add
font-variant-numeric: tabular-nums;to the table so every digit is the same width and right-aligned numbers line up perfectly. - Stripes plus hover: both rules have the same specificity, and the hover rule comes later in the output, so hovering a striped row still shows the hover colour.
- Empty cells: put an en dash or “—” in empty cells rather than leaving them blank, so readers know the value is missing on purpose.
The trap is sticky headers. A common trick is thead th { position: sticky; top: 0; } so the header stays visible while scrolling. But when you set a corner radius, the generated CSS adds overflow: hidden to the table, and an element with overflow: hidden becomes the scroll container that sticky positioning is measured against. Since the table itself doesn’t scroll, the header never sticks. Options: set radius to 0 for long tables that need sticky headers, round a wrapping div instead, or try overflow: clip, which clips without creating a scroll container in modern browsers.
For very wide tables on phones, the scrolling wrapper mentioned above is still the most reliable fix. If your content lives in Markdown, the Markdown Table Generator helps you draft the rows and columns; once your Markdown renderer turns it into HTML, add the class and these styles apply.
Worked examples
Dense data table
Header #1e3a8a, borders on all cells, no stripes, hover on, padding 8px, radius 0, font 14px, numbers right-aligned:
.styled-table {
width: 100%;
border-collapse: separate;
border-spacing: 0;
font: 14px/1.4 system-ui, sans-serif;
color: #1e293b;
background: #ffffff;
border: 1px solid #e2e8f0;
}
.styled-table th,
.styled-table td {
padding: 8px 10px;
text-align: left;
border-bottom: 1px solid #e2e8f0;
border-right: 1px solid #e2e8f0;
}
.styled-table tbody tr:hover {
background: #e0e3ef;
}
.styled-table th:not(:first-child),
.styled-table td:not(:first-child) {
text-align: right;
}
With radius 0, no border-radius or overflow lines are written at all. White header text on #1e3a8a scores 10.36:1.
Where the hover colour comes from
The hover background is not a separate setting. The default teal header #0f766e gives a hover of #ddeceb; the navy above gives #e0e3ef. Change the header colour and the hover tint follows, keeping the table on-brand without an extra decision.
Pro tips
- Choose a stripe colour only slightly darker than white; strong stripes compete with the header.
- Right-align numbers but keep text columns left-aligned — the alignment option deliberately skips the first column.
- Keep cell font size at 14px or more; data tables are read closely and small text tires eyes fast.
Glossary
- border-collapse
- Whether adjacent table cell borders merge into one (collapse) or stay separate.
- scope
- An attribute on th that tells assistive technology whether a header labels a column or a row.
- Tabular numerals
- Digits that all have the same width, so columns of numbers line up.
Frequently asked questions
Why isn’t border-radius working on my table?
It needs border-collapse: separate (with border-spacing: 0) and overflow: hidden.
How do I make a table responsive?
Wrap it in a div with overflow-x: auto so it can scroll horizontally on phones.
Should I use tables for layout?
No — only for tabular data. Use Grid or Flexbox for layout.
Why don’t the header colours apply to my table?
The selector is .styled-table thead th, so your header cells must be th elements inside a thead. Check the class name on the table too.
Why does my sticky header stop working when I add rounded corners?
Rounded corners add overflow: hidden, which makes the table its own scroll container, so sticky positioning has nothing to stick to. Set the radius to 0 or round a wrapper instead.
Can I use this CSS on several tables on one page?
Yes. Add class="styled-table" to each one; the rules are scoped to that class.
Last updated 2026-11-28 · Built by Vinayak Agarwal · Part of CSS & Design (37 tools)