The flex-wrap property controls whether flex items stay on one line or wrap onto multiple lines. It is essential for responsive layouts that adapt to different screen sizes and orientations.
01
nowrap
Single line.
02
wrap
Multi-line flow.
03
wrap-reverse
Reverse lines.
04
Container
On parent.
05
Responsive
Adapt layouts.
06
flex-flow
Shorthand pair.
Fundamentals
Introduction
The flex-wrap property in CSS is used in flexbox layouts to control whether flex items are forced onto one line or can wrap onto multiple lines. This property is essential for creating responsive designs that adapt to different screen sizes and orientations.
Definition and Usage
Apply flex-wrap on a flex container with display: flex or display: inline-flex. Use wrap for card grids, tag lists, and toolbars where items should move to the next line when horizontal space runs out. Use nowrap when every item must stay on a single row or column.
💡
Beginner Tip
By default, flex items try to stay on one line (nowrap). If items overflow or get squashed, try flex-wrap: wrap so they flow onto new lines instead.
Foundation
📝 Syntax
The syntax for the flex-wrap property is simple and can be applied to any flex container:
The default value of the flex-wrap property is nowrap, meaning that all flex items will be kept on a single line, even if they overflow the container.
Syntax Rules
Apply on the flex container, not on individual flex items.
Requires display: flex or display: inline-flex on the same element.
Accepts exactly three keyword values: nowrap, wrap, and wrap-reverse.
The property is not inherited.
Wrapping behavior depends on the main axis set by flex-direction.
Cheat Sheet
⚡ Quick Reference
Question
Answer
Initial value
nowrap
Applies to
Flex containers
Inherited
No
Value type
Keyword (nowrap, wrap, wrap-reverse)
Common pattern
display: flex; flex-wrap: wrap; for responsive grids
Reference
💎 Property Values
Value
Description
nowrap
All flex items are kept on a single line. Overflow is not prevented — items may shrink or spill outside the container.
wrap
Flex items wrap onto multiple lines from top to bottom (in a row flex container) when they run out of space along the main axis.
wrap-reverse
Flex items wrap onto multiple lines in the reverse cross-axis direction — from bottom to top in a row flex container.
nowrap vs wrap
With nowrap, four 100px items inside a 200px container stay on one row and overflow or shrink. With wrap, the same items break into two rows of two, keeping readable sizes without horizontal scrolling.
Preview
👀 Live Preview
A 220px container with four 90px items using flex-wrap: wrap — items flow onto a second line when they no longer fit:
Item 1Item 2Item 3Item 4
Hands-On
Examples Gallery
In this example, we’ll create a flex container with items that wrap onto multiple lines — plus nowrap comparison, wrap-reverse, and a responsive tag list.
🔀 Multi-Line Layouts
Start with the reference example — items that wrap when the container is too narrow.
Example 1 — Flex Container with Wrapping Items
Four 100px items inside a 200px container wrap onto two rows when flex-wrap: wrap is set.
Tags keep their natural width and flow onto new lines as the container narrows — no fixed column count required.
A11y
♿ Accessibility
Keep logical DOM order — wrapping is visual; screen readers follow source order, not line breaks.
Ensure wrapped items remain reachable with keyboard navigation on every viewport size.
Do not rely on line position alone to communicate meaning or priority.
Maintain enough spacing between wrapped items so touch targets do not overlap.
Test with zoom and small screens to confirm wrapped content stays readable.
🧠 How flex-wrap Works
1
Items fill the main axis
Flex items are placed along the main axis until the current line runs out of space.
First line
2
Wrap decides the next step
With nowrap, items stay on one line. With wrap, overflow moves to a new line.
Keyword
3
New lines stack on the cross axis
wrap adds lines downward; wrap-reverse adds them in the opposite direction.
Cross axis
=
🔀
Responsive multi-line layout
Content adapts to container width without horizontal scrolling or crushed items.
Compatibility
🖥 Browser Compatibility
The flex-wrap property is widely supported in all modern browsers, including the latest versions of Chrome, Firefox, Safari, Edge, and Opera. You can use it confidently in production projects.
✓ Baseline · Universal support
flex-wrap everywhere
All three keyword values work consistently in every modern browser as part of standard Flexbox.
99%Universal support
Google Chrome29+ · Desktop & Mobile
Full support
Mozilla Firefox28+ · Desktop & Mobile
Full support
Apple Safari9+ · macOS & iOS
Full support
Microsoft Edge12+ · All versions
Full support
Opera17+ · Modern versions
Full support
flex-wrap property99% supported
Bottom line:flex-wrap is safe for all modern projects. Pair it with flex-direction or use the flex-flow shorthand.
Wrap Up
🎉 Conclusion
The flex-wrap property is a valuable tool for web developers looking to create flexible and responsive layouts. By allowing flex items to wrap onto multiple lines, you can design layouts that adapt to various screen sizes and orientations, providing a better user experience.
Experiment with different values of flex-wrap to see how they can enhance the look and functionality of your web projects. For beginners, remember: default is nowrap, use wrap for responsive grids, and wrap-reverse when lines should stack in the opposite direction.
Use flex-wrap: wrap for card grids, tags, and chip lists
Combine with gap for consistent spacing between wrapped items
Pair with align-content to control spacing between wrapped lines
Use flex-flow: row wrap as a concise shorthand when needed
Test layouts at multiple viewport widths
❌ Don’t
Apply flex-wrap on flex items instead of the container
Assume wrapping happens automatically — the default is nowrap
Use wrap-reverse without checking that visual order still makes sense
Forget that nowrap can cause overflow or heavy shrinking
Rely on wrapping alone when a CSS Grid layout may be clearer
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about flex-wrap
Use these points when building multi-line flex layouts.
5
Core concepts
🔀01
Line breaking
Controls wrapping.
Purpose
nowrap02
Default nowrap
Single line.
Default
wrap03
Three values
nowrap, wrap, reverse.
Values
📂04
Container only
On parent.
Target
📱05
Responsive
Adapts to width.
Use case
❓ Frequently Asked Questions
The flex-wrap property controls whether flex items stay on one line or wrap onto multiple lines when they do not fit inside the flex container along the main axis.
The default value is nowrap, which keeps all flex items on a single line even if they overflow the container.
wrap moves overflowing items to new lines from top to bottom in a row container. wrap-reverse fills new lines in the opposite cross-axis direction, so lines appear from bottom to top.
flex-wrap applies to the flex container (the element with display: flex), not to individual flex items.
flex-wrap only controls wrapping. flex-flow is a shorthand that sets both flex-direction and flex-wrap in one declaration.