Understanding the flex-wrap Property in Flexbox
The flex-wrap property in CSS defines whether flex items should stay on a single line or wrap onto multiple lines when they overflow the flex container. It allows for more flexible and responsive layouts by controlling how items flow within a flex container.
nowrap (default): All flex items are placed on a single line, and they may overflow the container.
wrap: Flex items wrap onto multiple lines from top to bottom (in horizontal flex direction).
wrap-reverse: Flex items wrap onto multiple lines but in reverse order (from bottom to top).
In this example, when the width of the flex container is too small to fit all items in one line, flex-wrap: wrap causes the extra items to move to the next line instead of overflowing.
Use flex-wrap: wrap for responsive designs where items should move to new lines on smaller screens.
Combine flex-wrap with align-content to control spacing between multiple lines.
Avoid using nowrap when items have fixed widths that can cause overflow issues.
You're building a product grid on a mobile page, and the items are squeezing into a single row instead of wrapping. How would you fix it using flex-wrap?
If I set flex-wrap: wrap on a container but the items still don't wrap on a tablet, what’s the first thing you’d check?
What happens if you forget to set flex-wrap and the container has a fixed width with too many items?
Our product card component works fine on desktop, but on mobile, the text overflows and breaks the layout. How would you use flex-wrap to fix this without hardcoding heights?
A teammate says flex-wrap: wrap is causing inconsistent spacing between rows — how would you investigate and resolve this?
We have a dynamic list of tags that should wrap, but sometimes they overflow on smaller screens. What’s your approach to make this robust?
You're designing a responsive navigation bar that switches from horizontal to vertical on mobile — how do you use flex-wrap to avoid layout jank during resize, and what edge cases do you watch for?
In a component library, flex-wrap is used inconsistently across components. How would you standardize its usage to ensure predictable behavior across devices and content lengths?
A high-traffic page has a dynamic tag cloud that wraps poorly on low-end devices. How would you optimize the flex-wrap implementation for performance and rendering stability?
We’re migrating a legacy UI from floats to flexbox, and flex-wrap is causing cascading layout breaks in 30+ components. How would you approach this migration without breaking production?
How would you design a cross-team CSS architecture guideline for flex-wrap usage that balances flexibility, accessibility, and performance across 50+ micro-frontends?
A global product uses flex-wrap in a multilingual UI where text length varies by 300% between languages. How do you ensure layout integrity and avoid content clipping at scale?