Bird
Raised Fist0
Tailwindmarkup~20 mins

Gap between flex children in Tailwind - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Flex Gap Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
What does the Tailwind class gap-4 do in a flex container?
In a flex container, what is the effect of adding the class gap-4 to the parent element?
Tailwind
<div class="flex gap-4">
  <div class="bg-blue-500 p-4">Box 1</div>
  <div class="bg-red-500 p-4">Box 2</div>
  <div class="bg-green-500 p-4">Box 3</div>
</div>
AIt adds a 1rem space between each flex child horizontally and vertically.
BIt adds a 4px space between each flex child only horizontally.
CIt adds a 4rem space between the flex container and its children.
DIt adds padding inside each flex child of 4 units.
Attempts:
2 left
💡 Hint
Think about how Tailwind's spacing scale works and what 'gap' controls in flexbox.
📝 Syntax
intermediate
2:00remaining
Which Tailwind class correctly adds horizontal gap only between flex children?
You want to add space only between flex children horizontally, not vertically. Which Tailwind class should you use?
Tailwind
<div class="flex ???">
  <div class="bg-yellow-400 p-3">Item 1</div>
  <div class="bg-yellow-600 p-3">Item 2</div>
  <div class="bg-yellow-800 p-3">Item 3</div>
</div>
Agap-x-6
Bgap-y-6
Cgap-6
Dspace-x-6
Attempts:
2 left
💡 Hint
Tailwind has separate classes for horizontal and vertical gaps.
❓ rendering
advanced
2:30remaining
What is the visual difference between gap-8 and space-x-8 in a flex row?
Given a flex container with three boxes in a row, what will you see if you use gap-8 versus space-x-8?
Tailwind
<div class="flex gap-8">
  <div class="bg-purple-400 p-4">Box A</div>
  <div class="bg-purple-600 p-4">Box B</div>
  <div class="bg-purple-800 p-4">Box C</div>
</div>
A<code>gap-8</code> adds padding inside the container; <code>space-x-8</code> adds gaps vertically only.
B<code>gap-8</code> adds margin only to the right of each child; <code>space-x-8</code> adds padding inside each child.
C<code>gap-8</code> adds equal 2rem gaps between all children horizontally and vertically; <code>space-x-8</code> adds 2rem margin only to the left of all children except the first.
D<code>gap-8</code> and <code>space-x-8</code> produce identical spacing in all directions.
Attempts:
2 left
💡 Hint
Consider how CSS gap differs from margin spacing on children.
❓ selector
advanced
2:30remaining
Which Tailwind class combination correctly adds vertical gap and horizontal space between flex children?
You want vertical gaps of 1.5rem and horizontal space of 2rem between flex children. Which class combination achieves this?
Tailwind
<div class="flex ???">
  <div class="bg-pink-300 p-3">Child 1</div>
  <div class="bg-pink-500 p-3">Child 2</div>
  <div class="bg-pink-700 p-3">Child 3</div>
</div>
Agap-x-6 space-y-8
Bgap-6 space-x-8
Cgap-y-8 space-x-6
Dgap-y-6 space-x-8
Attempts:
2 left
💡 Hint
Remember Tailwind's spacing scale: 6 = 1.5rem, 8 = 2rem.
❓ accessibility
expert
3:00remaining
How does using gap in flex layouts improve accessibility compared to using margins for spacing?
Why is using the CSS gap property (and Tailwind's gap-* classes) better for accessibility than adding margins like space-x-* on flex children?
ABecause margins cause screen readers to skip elements, while <code>gap</code> hides them visually but keeps them accessible.
BBecause <code>gap</code> maintains consistent spacing even when flex items wrap or reorder, preserving layout clarity for screen readers and keyboard navigation.
CBecause <code>gap</code> automatically adds ARIA labels to flex children, improving semantic meaning.
DBecause margins increase the clickable area of flex children, which can confuse keyboard users.
Attempts:
2 left
💡 Hint
Think about how spacing behaves when flex items wrap or reorder.

Practice

(1/5)
1. What does the gap-x-4 class do when applied to a flex container in Tailwind CSS?
easy
A. Centers flex children horizontally
B. Adds vertical space between flex children
C. Removes all space between flex children
D. Adds horizontal space between flex children

Solution

  1. Step 1: Understand the gap-x-4 utility

    The gap-x-4 class adds horizontal spacing between flex children, specifically on the x-axis.
  2. Step 2: Differentiate from vertical gap

    Vertical spacing between flex children is controlled by gap-y-* classes, not gap-x-4.
  3. Final Answer:

    Adds horizontal space between flex children -> Option D
  4. Quick Check:

    Horizontal gap = gap-x-4 [OK]
Hint: Remember x = horizontal gap, y = vertical gap [OK]
Common Mistakes:
  • Confusing gap-x with gap-y
  • Thinking gap-x removes space
  • Assuming gap-x centers items
2. Which Tailwind CSS class correctly adds a 1rem gap between flex children both horizontally and vertically?
easy
A. gap-4
B. gap-x-1
C. gap-y-4
D. gap-1

Solution

  1. Step 1: Understand the gap-4 class

    The gap-4 class adds a uniform gap of 1rem (16px) both horizontally and vertically between flex children.
  2. Step 2: Differentiate from axis-specific gaps

    gap-x-1 and gap-y-4 add gaps only on one axis, and gap-1 adds a smaller gap (0.25rem).
  3. Final Answer:

    gap-4 -> Option A
  4. Quick Check:

    Uniform gap = gap-4 [OK]
Hint: Use gap-* for both axes, gap-x-* or gap-y-* for one axis [OK]
Common Mistakes:
  • Using gap-x or gap-y when both gaps are needed
  • Confusing gap-1 with gap-4 size
  • Assuming gap-1 equals 1rem
3. Given this HTML snippet:
<div class="flex gap-x-6">
  <div>Item 1</div>
  <div>Item 2</div>
  <div>Item 3</div>
</div>

What visual effect will the gap-x-6 class produce?
medium
A. Adds 1.5rem horizontal space between each item
B. Adds 1.5rem vertical space between each item
C. Adds 6rem horizontal space between each item
D. No space added between items

Solution

  1. Step 1: Interpret gap-x-6 size

    In Tailwind, gap-x-6 means horizontal gap of 1.5rem (24px) between flex children.
  2. Step 2: Confirm axis and spacing

    Since the container is flex (default row), gap-x-6 adds horizontal space, not vertical.
  3. Final Answer:

    Adds 1.5rem horizontal space between each item -> Option A
  4. Quick Check:

    gap-x-6 = 1.5rem horizontal gap [OK]
Hint: Tailwind gap-6 equals 1.5rem spacing [OK]
Common Mistakes:
  • Mixing horizontal and vertical gap
  • Thinking gap-x-6 means 6rem
  • Assuming no gap is added
4. You want to add a 2rem gap between flex children horizontally, but your code uses gap-x-8 and the gap looks smaller than expected. What is the likely mistake?
medium
A. Tailwind's gap-x-8 is 2rem, so no mistake
B. You forgot to add flex class to the container
C. You should use gap-8 instead of gap-x-8
D. The children have margin that overrides gap

Solution

  1. Step 1: Check if container is flex

    The gap-x-8 class only works if the container is a flex or grid container. Without flex, gap won't apply.
  2. Step 2: Confirm gap-x-8 size

    gap-x-8 equals 2rem horizontal gap, so the size is correct if flex is present.
  3. Final Answer:

    You forgot to add flex class to the container -> Option B
  4. Quick Check:

    gap-x-* needs flex container [OK]
Hint: Always add flex or grid for gap-x-* to work [OK]
Common Mistakes:
  • Assuming gap works without flex/grid
  • Confusing gap-x-8 size
  • Ignoring margin conflicts
5. You have a flex container with 3 children. You want 1rem vertical gap and 2rem horizontal gap between them. Which Tailwind classes should you use?
hard
A. flex gap-4 gap-8
B. flex gap-x-4 gap-y-8
C. flex gap-x-8 gap-y-4
D. flex gap-8 gap-y-4

Solution

  1. Step 1: Convert rem to Tailwind gap scale

    1rem = 4 (gap-4), 2rem = 8 (gap-8) in Tailwind spacing scale.
  2. Step 2: Assign horizontal and vertical gaps

    Horizontal gap (x-axis) should be 2rem -> gap-x-8. Vertical gap (y-axis) should be 1rem -> gap-y-4.
  3. Step 3: Verify class combination

    Using flex gap-x-8 gap-y-4 correctly sets horizontal and vertical gaps as required.
  4. Final Answer:

    flex gap-x-8 gap-y-4 -> Option C
  5. Quick Check:

    Horizontal 2rem = gap-x-8, Vertical 1rem = gap-y-4 [OK]
Hint: Use gap-x-* for horizontal and gap-y-* for vertical gaps [OK]
Common Mistakes:
  • Mixing gap-x and gap-y values
  • Using gap-* alone for different axis gaps
  • Confusing Tailwind spacing scale
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard