Tables show up everywhere in web apps.
Data dashboards need them. Pricing pages use them. Admin panels can't live without them. They organize information in a way that makes sense to our brains.
But here's the problem: default HTML tables look terrible. Gray borders, cramped spacing, zero personality. It's like they're stuck in 1995.
Good news though. With Tailwind CSS, you can turn those boring tables into something people actually want to look at. And you don't need to write a single line of custom CSS to do it.
Let's start simple. A good-looking table needs proper structure first, then styling second.
Your table should have <thead> for headers and <tbody> for data rows. This isn't just semantic HTML nonsense. It actually helps with styling because you can target these sections differently.
Here's where Tailwind shines. You can add padding, borders, and colors directly in your markup.
The first decision you'll make is about borders. Tailwind gives you two options:
border-collapse merges adjacent cell borders into oneborder-separate keeps each cell border distinctMost of the time, you want border-collapse. It looks cleaner and prevents that weird double-border effect.
```html
Product
Price
Stock
Laptop
$999
In Stock
Mouse
$29
Low Stock
```
Notice how px-4 py-2 gives each cell breathing room. Without padding, your data looks cramped and hard to read. The bg-gray-100 on the header row helps distinguish it from the body.
That's your foundation. Clean structure, consistent borders, good spacing.
Zebra stripes aren't just for animals. They make tables way easier to read, especially when you're scanning across long rows of data.
Tailwind makes this stupid simple with the odd: and even: variants. Just add them to your table rows.
Want every other row to be gray? Use odd:bg-gray-50 on your <tr> tags. Done.
```html
Name
Email
Role
John Doe
john@example.com
Admin
Jane Smith
jane@example.com
Editor
Bob Johnson
bob@example.com
Viewer
```
Hover effects are just as easy. Add hover:bg-blue-50 to your rows and they'll highlight when users mouse over them. This is huge for usability – it helps people keep track of which row they're looking at.
You can combine both. Striped rows plus hover state:
```html
...
```
I threw in cursor-pointer and transition-colors too. The pointer cursor tells users the row is interactive, and the transition makes the color change smooth instead of jarring.
Tables on mobile are a nightmare. They're wide, they break layouts, and they make users scroll horizontally – which nobody likes doing.
The simplest fix is wrapping your table in a container with overflow-x-auto. This lets users scroll the table horizontally while keeping your page layout intact.
```html
Employee
Position
Department
Location
Salary
Sarah Connor
Engineering Lead
Product Development
San Francisco
$145,000
```
Notice the whitespace-nowrap on the cells. This prevents text from wrapping, which keeps your columns readable when scrolling.
You can also adjust table behavior at different breakpoints. Maybe you want a fixed layout on desktop but auto layout on mobile:
```html
```
This gives you full control over how your tables behave across devices. Simple wrapper, big impact.
Sometimes you need more control over how your table columns behave. That's where table-auto and table-fixed come in.
table-auto is the default. Columns size themselves based on content. Long content gets wider columns, short content gets narrower columns. It's flexible but can be unpredictable.
table-fixed gives you complete control. Columns are sized based on the width you set, and content is forced to fit. This is perfect for data tables where you want consistent column widths.
```html
Task
Assignee
Status
Notes
Update documentation
Alex Chen
In Progress
Waiting for review from team lead
```
See how each column width is controlled with w-1/4, w-1/6, etc? No surprises, no shifting layouts.
Vertical alignment matters too. By default, table cells center their content vertically. But you can change that:
align-top pushes content to the topalign-middle keeps it centered (default)align-bottom pushes it to the bottomThis is super useful when you have cells with different amounts of content or when mixing text with images or badges.
```html
Top aligned content
Middle aligned content
Bottom aligned content
```
These utilities give you pixel-perfect control over your table layouts without fighting against browser defaults or writing custom CSS.
That's everything you need to style tables with Tailwind CSS. From basic borders and padding to complex responsive layouts with custom column widths and alignment.
The best part? It's all utility classes. No CSS files to maintain, no specificity wars, no mysterious layout bugs. Just clean, readable HTML that does exactly what you want.
Start with the basics – borders, padding, colors. Then add striped rows and hover effects. Make it responsive with overflow containers. And when you need precision control, reach for fixed layouts and alignment utilities.
Your tables will look better, and your users will thank you for it.
Get notified when we add new templates, components, and more!
WindyBase is a weekly curated Tailwind CSS template and tool directory built for the modern developer.
© 2025 WindyBase. All rights reserved.