Space between two rows in a table?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
In HTML tables, adding vertical space between rows is not as simple as adding margin to a tr. Table layout has its own rules, so some CSS properties behave differently from normal block elements.
The right technique depends on what kind of spacing you want. Sometimes you want actual gaps between rows, and sometimes you just want the cells to feel taller and less cramped.
Why margin on tr Usually Fails
A common first attempt is something like this:
That usually does not create visible space between table rows, because table rows do not participate in layout the same way ordinary block elements do.
If your goal is visual spacing, use one of these instead:
- increase cell padding
- use
border-spacingon the table - add borders or background tricks for row separation
Option 1: Increase Cell Padding
If you want rows to feel taller, padding on the cells is the simplest and most robust option:
This does not create an actual empty gap between rows, but it often solves the design problem because the content has more breathing room.
Option 2: Use border-spacing for Real Gaps
If you want real space between rows, use border-spacing on the table and make sure the table is using the separate border model:
The 0 10px means no horizontal gap and 10px of vertical gap between rows.
This is the closest CSS answer to "put space between rows." It is also the solution people often miss because border-spacing does nothing when border-collapse: collapse is still active.
Option 3: Add Extra Space Below Specific Rows
Sometimes you do not want every row spaced equally. You only want one row to have extra separation. In that case, use padding on that row's cells through a class:
This does not create a separate gap object, but it produces visible extra space after one row without changing the whole table layout.
Choosing the Right Approach
Use cell padding when the table simply looks cramped. Use border-spacing when you truly want visible row gaps. Use row-specific cell classes when only some rows need separation.
There is no single universal best answer because tables are often constrained by border styles, background colors, zebra striping, and browser defaults.
If the design includes row backgrounds or card-like rows, border-spacing plus border-collapse: separate is often the strongest option. If the table has classic grid borders, padding may be easier to control.
Common Pitfalls
The biggest pitfall is trying to use margin on tr or td and expecting block-layout behavior. Tables do not work that way.
Another common issue is setting border-spacing while still using border-collapse: collapse. In that mode, the spacing setting has no visible effect.
People also forget that extra padding changes row height, not true row separation. That can be perfectly fine, but it is not the same thing as an actual gap.
Finally, if you use background colors, check how the gap should look. With border-spacing, the table background may show through between rows, so set backgrounds intentionally on the table and cells.
Summary
- '
marginontrusually does not create space between table rows.' - Use cell
paddingwhen you want rows to feel taller. - Use
border-spacingwithborder-collapse: separatewhen you want real gaps between rows. - For extra space after one row, target that row's cells with a class and more bottom padding.
- Pick the technique based on whether you need true gaps or just more comfortable row height.

