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
Recall & Review
beginner
What does the Tailwind CSS class space-x-4 do?
It adds horizontal space (gap) of 1rem (4 units) between all direct child elements inside a container.
Click to reveal answer
beginner
How does space-y-2 affect child elements in Tailwind CSS?
It adds vertical space (gap) of 0.5rem (2 units) between all direct child elements stacked vertically.
Click to reveal answer
intermediate
Can space-x and space-y be used together on the same container?
Yes, you can use both to add horizontal and vertical spacing between children, useful in grid or flex layouts with multiple rows and columns.
Click to reveal answer
intermediate
What type of layout is required for space-x and space-y to work properly?
They work best with flexbox or grid layouts where children are direct siblings inside a container.
Click to reveal answer
intermediate
Why is using space-x or space-y better than adding margin to each child?
Because it automatically manages consistent spacing only between children without extra margin on the container edges, making layout cleaner and easier to maintain.
Click to reveal answer
What does space-x-6 do in Tailwind CSS?
AAdds 1.5rem horizontal space between child elements
BAdds 1.5rem vertical space between child elements
CAdds 6px horizontal space between child elements
DAdds 6rem vertical space between child elements
✗ Incorrect
space-x-6 adds horizontal spacing of 1.5rem (6 units) between children.
Which layout method is needed for space-y to work correctly?
AFloat layout
BFlexbox or Grid
CPosition absolute
DTable layout
✗ Incorrect
space-y works with flexbox or grid where children are siblings stacked vertically.
If you want vertical space between children, which class should you use?
Aspace-l
Bspace-x
Cspace-b
Dspace-y
✗ Incorrect
space-y adds vertical spacing between children.
What happens if you add space-x-4 to a container with only one child?
ANo visible space is added
B4rem margin is added around the child
CChild gets 4rem padding
DContainer gets 4rem padding
✗ Incorrect
Spacing applies only between siblings, so one child means no space added.
Why might space-x be preferred over adding margin-right to each child?
AIt adds padding instead of margin
BIt only works with grid
CIt avoids extra margin on the last child
DIt disables flexbox
✗ Incorrect
space-x automatically skips margin on the last child, keeping layout neat.
Explain how space-x and space-y classes work in Tailwind CSS and when to use them.
Think about spacing between siblings in a row or column.
You got /4 concepts.
Describe a real-life example where using space-x or space-y improves layout compared to manual margins.
Imagine buttons or cards spaced nicely without extra margin on edges.
You got /4 concepts.
Practice
(1/5)
1. What does the Tailwind class space-x-4 do when applied to a container with multiple child elements?
easy
A. Adds padding of 1rem inside each child element
B. Adds horizontal space of 1rem between each child element
C. Adds vertical space of 1rem between each child element
D. Adds margin of 1rem around the container
Solution
Step 1: Understand the space-x class
The space-x class adds horizontal space between child elements inside a container.
Step 2: Interpret the number 4
In Tailwind, 4 corresponds to 1rem (16px) spacing.
Final Answer:
Adds horizontal space of 1rem between each child element -> Option B
Hint: Use space-y for vertical stacks, space-x for horizontal rows [OK]
Common Mistakes:
Expecting vertical space from space-x
Thinking space-x breaks vertical layout
Confusing margin and space utilities
5. You have a grid of cards arranged in 3 columns. You want to add 1rem horizontal space between columns and 0.5rem vertical space between rows using Tailwind. Which class combination should you use on the grid container?
hard
A. space-x-4 space-y-2
B. space-x-2 space-y-4
C. space-x-4 space-y-4
D. space-x-2 space-y-2
Solution
Step 1: Match spacing values to Tailwind scale
1rem corresponds to 4 and 0.5rem corresponds to 2 in Tailwind spacing scale.
Step 2: Assign horizontal and vertical spacing
Horizontal space between columns uses space-x-4, vertical space between rows uses space-y-2.