CSS flex-wrap
Property
The flex-wrap
property in CSS controls whether flex items wrap onto multiple lines when they don’t fit in a single row or column.
1. Syntax
Value | Description |
---|---|
nowrap (default) | All flex items stay on one line, even if they overflow. |
wrap | Flex items wrap to a new line if needed. |
wrap-reverse | Flex items wrap in reverse order (bottom to top or right to left). |
2. Basic Example
✅ Flex Container with wrap
✅ Items wrap onto multiple lines if the container is too small.
✅ nowrap
(Default – No Wrapping)
✅ All items stay in one row (overflowing if necessary).
✅ wrap-reverse
(Reverse Wrapping)
✅ Items wrap in reverse order (bottom-to-top or right-to-left).
3. Combining with flex-direction
The wrapping behavior changes based on flex-direction
:
row
(default) → Wraps to a new row belowcolumn
→ Wraps to a new column to the right
✅ Items wrap into a new column instead of a new row.
4. Best Practices
✔ Use flex-wrap: wrap;
for responsive layouts.
✔ Avoid nowrap
if elements overflow the container.
✔ Combine with justify-content
for better alignment.