CSS flex-wrap & gap
- type
- property (on the flex container)
- applies to
- a flex container
- inherits
- no
- common values
- flex-wrap: nowrap (default)/wrap; gap: 12px
Where it goes
On the flex parent, whenever items should wrap on small screens or need even spacing.
Example
.row {
display: flex;
flex-wrap: wrap;
gap: 16px;
}Common mistakes
- Forgetting flex-wrap on a row that should reflow on phones. Without it, the items shrink and squeeze instead of wrapping.
- Using margin on each item for spacing instead of gap on the parent. gap does not add extra space at the ends the way margins do.