📖 Scenario: You are creating a simple webpage section that displays three colored boxes in a row. You want to control how these boxes are spaced horizontally using Tailwind CSS's justify-content utilities.
🎯 Goal: Build a horizontal row of three colored boxes inside a container. Use Tailwind CSS classes to set the container as a flexbox and apply different justify-content values to align the boxes along the main axis.
📋 What You'll Learn
Create a container <div> with Tailwind CSS flexbox class flex.
Add three child <div> boxes inside the container with distinct background colors and fixed width and height.
Add a Tailwind CSS class to the container to justify content along the main axis using justify-center.
Ensure the layout is responsive and the boxes remain horizontally aligned.
💡 Why This Matters
🌍 Real World
Web developers often need to align items horizontally in navigation bars, galleries, or toolbars. Using Tailwind CSS flexbox utilities makes this easy and consistent.
💼 Career
Understanding flexbox and justify-content is essential for front-end developers to create responsive, accessible layouts quickly using utility-first CSS frameworks like Tailwind.
Progress0 / 4 steps
1
Create the container and three boxes
Create a <div> container with the Tailwind CSS class flex. Inside it, create three child <div> elements with background colors bg-red-500, bg-green-500, and bg-blue-500. Each box should have fixed width w-24 and height h-24.
Tailwind
Hint
Use the Tailwind CSS class flex on the container to arrange children in a row. Give each box a background color and fixed size using bg-*, w-24, and h-24.
2
Add a justify-content configuration variable
Add a Tailwind CSS class justify-center to the container <div> to center the boxes horizontally along the main axis.
Tailwind
Hint
Use the Tailwind CSS class justify-center on the flex container to center the boxes horizontally.
3
Change justify-content to space-between
Replace the justify-center class on the container <div> with justify-between to space the boxes evenly with space between them.
Tailwind
Hint
Replace the justify-center class with justify-between to spread the boxes with space between them.
4
Add aria-label and responsive spacing
Add an aria-label="Color boxes container" attribute to the container <div> for accessibility. Also add the Tailwind CSS class gap-4 to add horizontal spacing between the boxes on all screen sizes.
Tailwind
Hint
Use the aria-label attribute on the container for screen readers. Add gap-4 class to create consistent spacing between boxes.
Practice
(1/5)
1. What does the Tailwind class justify-center do in a flex container?
easy
A. Centers items horizontally along the main axis
B. Aligns items to the start vertically
C. Distributes items evenly with space around
D. Stacks items vertically in a column
Solution
Step 1: Understand the main axis in flexbox
The main axis is horizontal by default in a flex container with flex-row.
Step 2: Effect of justify-center
This class centers all flex items horizontally along the main axis.
Final Answer:
Centers items horizontally along the main axis -> Option A
Quick Check:
justify-center = center horizontally [OK]
Hint: Justify content controls horizontal alignment in flex row [OK]
Common Mistakes:
Confusing justify with align items
Thinking justify-center aligns vertically
Mixing justify-between with justify-center
2. Which Tailwind class correctly justifies items to have equal space between them horizontally?
easy
A. justify-around
B. justify-end
C. justify-center
D. justify-between
Solution
Step 1: Recall the meaning of justify-between
The class justify-between places equal space between items, but no space at the ends.
Step 2: Compare with other options
justify-around adds space around items, justify-center centers them, and justify-end aligns to the right.
Final Answer:
justify-between -> Option D
Quick Check:
Equal space between items = justify-between [OK]
Hint: Between means space only between items, not edges [OK]
Common Mistakes:
Choosing justify-around instead of justify-between
B. Using justify-center instead of justify-between
C. Items need inline-block class
D. Should use justify-end for spacing
Solution
Step 1: Analyze the class used
The container uses justify-center, which centers items but does not add space between them.
Step 2: Correct class for spacing
To add equal space between items, justify-between should be used instead.
Final Answer:
Using justify-center instead of justify-between -> Option B
Quick Check:
Centering ≠ spacing between items [OK]
Hint: Use justify-between for spacing, not justify-center [OK]
Common Mistakes:
Confusing justify-center with justify-between
Adding unnecessary classes like inline-block
Thinking flex-row is missing when flex defaults to row
5. You want a navigation bar with 4 links spaced evenly across the width, but with extra space at the edges. Which Tailwind class should you use on the flex container?
hard
A. justify-center
B. justify-between
C. justify-around
D. justify-start
Solution
Step 1: Understand spacing requirements
The requirement is equal spacing between items and extra space at the container edges.
Step 2: Match with Tailwind classes
justify-around adds equal space around each item, including edges, unlike justify-between which has no edge space.
Final Answer:
justify-around -> Option C
Quick Check:
Space around items and edges = justify-around [OK]
Hint: Around means space on edges and between items [OK]
Common Mistakes:
Choosing justify-between which lacks edge space
Using justify-center which centers items only
Assuming justify-start spaces items evenly
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.