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
Create a Vertical List with Space Between Items Using Tailwind CSS
📖 Scenario: You are building a simple vertical list of items for a website. You want to add equal space between each item so the list looks neat and easy to read.
🎯 Goal: Build an HTML list where each item has vertical space between them using Tailwind CSS's space-y utility.
📋 What You'll Learn
Use a <ul> element with three <li> children
Add Tailwind CSS class space-y-4 to the <ul> to create vertical spacing
Each list item should contain the text: Item 1, Item 2, and Item 3 respectively
Use semantic HTML and ensure the list is accessible
💡 Why This Matters
🌍 Real World
Adding consistent spacing between elements is a common need in web design to improve readability and visual appeal.
💼 Career
Understanding how to use utility-first CSS frameworks like Tailwind CSS to control layout and spacing is valuable for front-end web development roles.
Progress0 / 4 steps
1
Create the HTML list structure
Create a <ul> element with three <li> children. The first <li> should have the text Item 1, the second Item 2, and the third Item 3.
Tailwind
Hint
Use <ul> for the list and add three <li> elements inside it with the exact texts.
2
Add Tailwind CSS class for vertical spacing
Add the Tailwind CSS class space-y-4 to the <ul> element to create vertical space between the list items.
Tailwind
Hint
Add the class space-y-4 inside the class attribute of the <ul> tag.
3
Add a container with padding around the list
Wrap the <ul> element inside a <div> with the Tailwind CSS class p-6 to add padding around the list.
Tailwind
Hint
Use a <div> with class p-6 to add padding around the list.
4
Add a heading above the list
Add a <h2> heading with the text My List above the <ul> inside the <div>. Add the Tailwind CSS classes text-xl and font-semibold to the heading for styling.
Tailwind
Hint
Add a heading with the exact text and classes above the list inside the container.
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.