Bird
Raised Fist0
CSSmarkup~20 mins

Flex wrap in CSS - Practice Problems & Coding Challenges

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Challenge - 5 Problems
🎖️
Flex Wrap Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
What does flex-wrap: wrap; do in a flex container?
Choose the correct description of the effect of flex-wrap: wrap; on flex items inside a flex container.
AIt centers all flex items horizontally inside the container.
BIt forces all flex items to stay on a single line, shrinking them if needed.
CIt allows flex items to move to the next line if they don't fit in one line.
DIt hides any flex items that don't fit in the container's width.
Attempts:
2 left
💡 Hint
Think about what happens when there are too many items to fit in one row.
📝 Syntax
intermediate
2:00remaining
Which CSS snippet correctly enables wrapping of flex items?
Select the CSS code that correctly applies wrapping behavior to a flex container.
CSS
div.container {
  display: flex;
  /* Which line below is correct? */
}
Aflex-wrap: wrap;
Bflex-wrap: nowrap;
Cflex-wrap: true;
Dwrap-flex: true;
Attempts:
2 left
💡 Hint
The property name is flex-wrap and the value to allow wrapping is wrap.
rendering
advanced
2:30remaining
What will be the visible layout result of this CSS?
Given the CSS below, how will the flex items be arranged visually in the browser?
CSS
div.container {
  display: flex;
  flex-wrap: wrap;
  width: 300px;
  border: 1px solid black;
}

div.item {
  flex: 0 0 140px;
  height: 50px;
  background-color: lightblue;
  margin: 5px;
}
AItems overlap each other inside the container.
BAll items in one row, shrinking to fit inside 300px.
CItems stacked vertically in a single column.
DTwo items per row, wrapping to next line after two items.
Attempts:
2 left
💡 Hint
Each item is 140px wide plus margin, container is 300px wide.
selector
advanced
2:30remaining
Which CSS selector targets only flex items that wrap to the next line?
You want to style only the flex items that appear on the second line after wrapping. Which selector will select those items?
Adiv.container > div.item:nth-child(n+3)
Bdiv.container > div.item:first-child
Cdiv.container > div.item:last-child
Ddiv.container > div.item:nth-child(2)
Attempts:
2 left
💡 Hint
Items that wrap to the next line start from the third item if two fit per line.
accessibility
expert
3:00remaining
How does using flex-wrap: wrap; affect keyboard navigation and accessibility?
Consider a flex container with many items that wrap onto multiple lines. What is the best practice to ensure keyboard users can navigate items logically?
ADisable wrapping to keep all items on one line for simpler navigation.
BEnsure the DOM order matches the visual order so tabbing moves through items in reading order.
CAdd ARIA roles to each flex item to force screen readers to read them in visual order.
DUse <code>tabindex="-1"</code> on wrapped items to skip them in keyboard navigation.
Attempts:
2 left
💡 Hint
Think about how keyboard users move through content and how DOM order affects that.

Practice

(1/5)
1. What does the CSS property flex-wrap: wrap; do in a flex container?
easy
A. It allows flex items to move to the next line if they don't fit in one row.
B. It forces all flex items to stay in a single line, even if they overflow.
C. It hides flex items that don't fit in the container.
D. It centers all flex items horizontally.

Solution

  1. Step 1: Understand the role of flex-wrap

    The flex-wrap property controls whether flex items stay in one line or wrap to new lines.
  2. Step 2: Identify the effect of wrap value

    The value wrap allows items to move to the next line if they don't fit in one row, preventing overflow.
  3. Final Answer:

    It allows flex items to move to the next line if they don't fit in one row. -> Option A
  4. Quick Check:

    Flex wrap = wrap items to next line [OK]
Hint: Wrap means items jump to next line if needed [OK]
Common Mistakes:
  • Thinking wrap hides items
  • Confusing wrap with centering
  • Assuming wrap forces one line
2. Which of the following is the correct CSS syntax to make flex items wrap onto multiple lines?
easy
A. flex-wrap: nowrap;
B. flex-wrap: wrap;
C. flex-wrap: no-wrap;
D. flex-wrap: wrap-all;

Solution

  1. Step 1: Recall valid values for flex-wrap

    The valid values are nowrap, wrap, and wrap-reverse.
  2. Step 2: Identify the correct syntax for wrapping

    The correct syntax to allow wrapping is flex-wrap: wrap;. Other options are invalid or incorrect.
  3. Final Answer:

    flex-wrap: wrap; -> Option B
  4. Quick Check:

    Correct syntax for wrap = flex-wrap: wrap; [OK]
Hint: Remember exact spelling: wrap, not no-wrap [OK]
Common Mistakes:
  • Using 'no-wrap' instead of 'nowrap'
  • Adding extra words like 'wrap-all'
  • Confusing wrap with nowrap
3. Given this CSS and HTML, what will happen when the browser width is too small to fit all items in one row?
div.container {
  display: flex;
  flex-wrap: wrap;
  width: 300px;
}
span.item {
  width: 140px;
  flex-shrink: 0;
  height: 50px;
  background: lightblue;
  margin: 5px;
}

<div class='container'> <span class='item'>1</span> <span class='item'>2</span> <span class='item'>3</span> </div>
medium
A. Only the first item is visible; others are hidden.
B. All three items stay in one row and overflow the container.
C. Items 1 and 2 stay in the first row; item 3 moves to the next line.
D. Items stack vertically ignoring flex rules.

Solution

  1. Step 1: Calculate space needed for items in one row

    Each item is 140px wide plus 5px margin on each side (total 150px). Two items fit in 300px width, but three do not.
  2. Step 2: Understand effect of flex-wrap: wrap;

    Because wrapping is allowed, the third item moves to the next line instead of overflowing.
  3. Final Answer:

    Items 1 and 2 stay in the first row; item 3 moves to the next line. -> Option C
  4. Quick Check:

    Wrap lets items jump to next line when no space [OK]
Hint: Wrap moves extra items to new line when no space [OK]
Common Mistakes:
  • Assuming all items stay in one line
  • Thinking items get hidden
  • Ignoring margin space in width calculation
4. You wrote this CSS but the flex items are not wrapping as expected:
div.box {
  display: flex;
  flex-wrap: wrap;
  width: 200px;
}
span.box-item {
  width: 150px;
  height: 40px;
  background-color: coral;
}

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

  1. 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.
  2. 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.
  3. Final Answer:

    The container width is too large to force wrapping. -> Option A
  4. 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

  1. Step 1: Understand wrap-reverse behavior

    The value wrap-reverse makes wrapped lines stack in reverse order, with new lines above the first.
  2. 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.
  3. Final Answer:

    flex-wrap: wrap-reverse; -> Option D
  4. 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