Flex wrap helps items in a container move to the next line when there is not enough space. This keeps your layout neat and readable.
When you want items in a row to wrap to the next line on small screens.
When you have a list of buttons or images that should not shrink too small.
When you want a flexible grid that adjusts to different screen sizes.
When you want to avoid horizontal scrolling caused by too many items in one line.
Syntax
CSS
flex-wrap: nowrap | wrap | wrap-reverse;
nowrap means all items stay in one line (default).
wrap lets items move to the next line if needed.
wrap-reverse wraps items but in reverse order vertically.
Examples
All items stay in one line, even if they overflow the container.
CSS
flex-wrap: nowrap;
Items move to the next line when they don't fit in one line.
CSS
flex-wrap: wrap;
Items wrap to the next line but the new line appears above the previous one.
CSS
flex-wrap: wrap-reverse;
Sample Program
This example shows a flex container with five items. The flex-wrap: wrap; property lets items move to the next line if they don't fit in the container's width. Try resizing the browser window to see the wrapping effect.
What is the most likely reason the items stay in one line and shrink?
medium
A. The container width is too large to force wrapping.
B. You forgot to set flex-wrap to wrap.
C. The items have no margin or padding, so they don't wrap.
D. The container has no height set, so wrapping is disabled.
Solution
Step 1: Check the container width and item widths
The container is 200px wide, each item is 150px wide, so two items can fit side by side.
Step 2: Understand wrapping behavior
Since two items fit in 200px, no wrapping is needed. Items stay in one line and shrink further if more items exist.
Final Answer:
The container width is too large to force wrapping. -> Option A
Quick Check:
Wrapping happens only if items exceed container width [OK]
Hint: Wrapping needs items wider than container width [OK]
Common Mistakes:
Assuming margin is required for wrap
Thinking height affects wrapping
Forgetting container width limits
5. You want a flex container that wraps items but reverses the order of wrapped lines (the new lines appear above the first line). Which CSS property and value combination achieves this?
hard
A. flex-wrap: wrap; flex-direction: row-reverse;
B. flex-wrap: reverse-wrap;
C. flex-wrap: nowrap; flex-direction: column;
D. flex-wrap: wrap-reverse;
Solution
Step 1: Understand wrap-reverse behavior
The value wrap-reverse makes wrapped lines stack in reverse order, with new lines above the first.
Step 2: Check other options for correctness
reverse-wrap is invalid. Using flex-direction: row-reverse reverses item order horizontally but not line stacking. nowrap disables wrapping.
Final Answer:
flex-wrap: wrap-reverse; -> Option D
Quick Check:
Wrap reverse stacks lines from bottom up [OK]
Hint: Use wrap-reverse to flip wrapped lines order [OK]
Common Mistakes:
Using invalid property values
Confusing flex-direction with wrap direction
Forgetting wrap disables wrapping
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.