# flex-wrap

> The `flex-wrap` CSS property defines whether the flex items should wrap onto multiple lines inside the flex container.

## How do I make flex items wrap to the next line?

The property that controls whether flex items are forced onto a single line or can wrap onto multiple lines within a flex container. It helps manage how items flow when there's not enough space, allowing for more flexible and responsive designs.

- Topic: Flexboxes
- Type: property
- Browser support: Chrome 29+, Chrome Android 29+, Edge 12+, Firefox 28+, Firefox Android 28+, Safari 9+, Safari iOS 9+

## Example

Wrong:

```css
.cards {
  display: flex;
}
.card {
  width: 300px;
}
```

Right:

```css
.cards {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
}
.card {
  flex: 1 1 300px;
}
```

Without `flex-wrap`, items shrink into one line; with it, they move to new lines once they hit 300px.

## Common mistakes

- Items never wrap because they all have `flex-shrink: 1` and no minimum size.
- The last row's items stretch wider than the others with `flex: 1`.

## Key points

- Responsive rows of cards use `flex-wrap: wrap` with a `flex-basis` or `min-width`, so items wrap instead of overflowing.
- Spacing between wrapped lines uses `gap`, not negative margins.

## Interview questions

### Why are my flex items not wrapping?

The default is 'nowrap', and items shrink first. Add `flex-wrap: wrap` and give items a basis or minimum width.

### How do I keep last-row items the same width?

Flexbox can't align items across rows. Use grid with `repeat(auto-fill, minmax(300px, 1fr))` for equal columns.

## Related cards

- [flex-flow](https://wonderium.dev/css/flex-flow.md)
- [flex-basis](https://wonderium.dev/css/flex-basis.md)
- [gap](https://wonderium.dev/css/gap.md)
- [align-content](https://wonderium.dev/css/align-content.md)
- [repeat()](https://wonderium.dev/css/repeat.md)

---

- Level: [CSS](https://wonderium.dev/css.md)
- HTML version: https://wonderium.dev/css/flex-wrap
- Last updated: 2026-11-25
