← Back to CSS
12

Tables in CSS: Readable, Compact and Responsive

Style tables so they stay readable with zebra rows, sensible alignment and responsive patterns that do not sacrifice clarity.

📘 Theory

A solid base for tables

Good readability starts with spacing and structure, not decoration.

Use `border-collapse` to remove awkward double borders and keep the grid visually cleaner.

Give cells enough padding and align text consistently. If the table mixes text and numbers, the alignment itself becomes part of the UX.

  • Keep text left-aligned by default.
  • Use lighter separators instead of heavy borders.
  • Add a caption when the table needs more context.

Zebra rows and hover states

These small touches make dense data easier to scan.

1

Alternating row backgrounds help the eye track information across the table, especially when several columns sit close together.

2

A hover state adds feedback during exploration and is particularly useful in dashboards or admin interfaces.

Responsive tables with horizontal scroll

This is often the safest solution for wide tables.

1

Wrap the table in a container with `overflow-x: auto` so the browser can preserve the column structure without squeezing cells into unreadable fragments.

2

A `min-width` on the table helps protect the layout and signals that scrolling is expected on smaller screens.

Stacked rows on mobile

Useful when the table has few columns and the mobile layout needs extra clarity.

1

The stacked pattern turns each row into a small card and uses `data-label` plus `::before` to expose the meaning of each value.

2

It works best on simple tables. If there are too many columns, horizontal scroll is usually cleaner and less verbose.

🧪 Learn by doing

Example Base table Start with a simple readable table and adjust the spacing if needed.
Example Horizontal scroll wrapper Practice the safest responsive pattern for wide datasets.

🏁 Challenges

Challenge Challenge: sticky table header Keep the table header visible while the user scrolls through the rows.

What is this?

I'm Cristian Eslava and I sometimes build websites so both you and I can learn and experiment. culTest

I made this in February 2026 to make learning easier for my students. The idea is to learn web development by practicing and to keep expanding the project with new topics, tests and challenges.

It draws inspiration from MDN, W3Schools, CodePen, Manz and many other web development references. I wanted to combine useful theory, runnable examples, challenges and the testing system I had already built for culTest. culTest

If you liked it, if you didn't, or if you want to get in touch, write to me at cristianeslava@gmail.com