gap-4
for simple spacing between items (row)
gap-4
adds a consistent 1rem space *between* flex items, horizontally here.
The "Gotcha" is that
justify-*
classes control spacing along the
main axis
.
For
flex-row
(default), this is horizontal. For
flex-col
, it's vertical.
gap-*
is often simpler and more direct for adding space *between* items, regardless of the main axis distribution.
justify-between
in
flex-col
:
With
flex-col justify-between
and a set height, items are pushed to the start, middle, and end of the container's vertical axis.
This might not be what you want if you just need consistent spacing *between* items.
gap-4
in
flex-col
(Often Simpler):
With
flex-col gap-4
, a 1rem space is added *between* each item vertically.
The container's height grows with content + gaps. This is often more intuitive for inter-item spacing.
Key Takeaway:
If you want space *between* items,
gap-*
is usually the most straightforward approach for both
flex-row
and
flex-col
. Use
justify-*
when you specifically need to distribute items along the entire length of the main axis (e.g., pushing items to the edges).