Justify content helps you control how items line up horizontally inside a container. It makes your layout look neat and balanced.
Justify content (main axis) in Tailwind
justify-start justify-center justify-end justify-between justify-around justify-evenly
These classes work only on flex containers (use flex class first).
They control horizontal alignment if flex direction is row (default).
<div class="flex justify-start">...</div><div class="flex justify-center">...</div><div class="flex justify-between">...</div><div class="flex justify-evenly">...</div>This page shows four boxes with three items each. Each box uses a different justify-* class to show how items align horizontally inside a flex container.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> <title>Justify Content Example</title> <script src="https://cdn.tailwindcss.com"></script> </head> <body class="p-6"> <h1 class="text-xl font-bold mb-4">Justify Content (Main Axis) Examples</h1> <section class="mb-6"> <h2 class="mb-2">justify-start (items to left)</h2> <div class="flex justify-start bg-gray-100 p-4 border rounded"> <div class="bg-blue-500 text-white px-4 py-2 rounded">Item 1</div> <div class="bg-blue-500 text-white px-4 py-2 rounded ml-2">Item 2</div> <div class="bg-blue-500 text-white px-4 py-2 rounded ml-2">Item 3</div> </div> </section> <section class="mb-6"> <h2 class="mb-2">justify-center (items centered)</h2> <div class="flex justify-center bg-gray-100 p-4 border rounded"> <div class="bg-green-500 text-white px-4 py-2 rounded">Item 1</div> <div class="bg-green-500 text-white px-4 py-2 rounded ml-2">Item 2</div> <div class="bg-green-500 text-white px-4 py-2 rounded ml-2">Item 3</div> </div> </section> <section class="mb-6"> <h2 class="mb-2">justify-between (space between items)</h2> <div class="flex justify-between bg-gray-100 p-4 border rounded"> <div class="bg-red-500 text-white px-4 py-2 rounded">Item 1</div> <div class="bg-red-500 text-white px-4 py-2 rounded">Item 2</div> <div class="bg-red-500 text-white px-4 py-2 rounded">Item 3</div> </div> </section> <section> <h2 class="mb-2">justify-evenly (equal space around)</h2> <div class="flex justify-evenly bg-gray-100 p-4 border rounded"> <div class="bg-purple-500 text-white px-4 py-2 rounded">Item 1</div> <div class="bg-purple-500 text-white px-4 py-2 rounded">Item 2</div> <div class="bg-purple-500 text-white px-4 py-2 rounded">Item 3</div> </div> </section> </body> </html>
Always add flex class to make the container a flexbox.
Justify content works on the main axis, which is horizontal by default.
Use justify-* classes to quickly control horizontal spacing without writing custom CSS.
Justify content controls horizontal alignment of items in a flex container.
Use classes like justify-start, justify-center, and justify-between to arrange items.
It helps make layouts look clean and balanced easily.
Practice
justify-center do in a flex container?Solution
Step 1: Understand the main axis in flexbox
The main axis is horizontal by default in a flex container withflex-row.Step 2: Effect of
This class centers all flex items horizontally along the main axis.justify-centerFinal Answer:
Centers items horizontally along the main axis -> Option AQuick Check:
justify-center = center horizontally [OK]
- Confusing justify with align items
- Thinking justify-center aligns vertically
- Mixing justify-between with justify-center
Solution
Step 1: Recall the meaning of justify-between
The classjustify-betweenplaces equal space between items, but no space at the ends.Step 2: Compare with other options
justify-aroundadds space around items,justify-centercenters them, andjustify-endaligns to the right.Final Answer:
justify-between -> Option DQuick Check:
Equal space between items = justify-between [OK]
- Choosing justify-around instead of justify-between
- Confusing justify-end with justify-between
- Using justify-center for spacing
<div class="flex justify-end"> <div>Item 1</div> <div>Item 2</div> </div>
Where will the items appear inside the container?
Solution
Step 1: Identify the flex container and class
The container usesflexandjustify-end, so it is a flex row with items justified to the end.Step 2: Understand justify-end effect
justify-endpushes all items to the right side (end) of the container horizontally.Final Answer:
Items aligned to the right side -> Option AQuick Check:
justify-end = right align items [OK]
- Thinking justify-end centers items
- Confusing justify-end with justify-start
- Assuming justify-end spaces items evenly
<div class="flex justify-center"> <div>A</div> <div>B</div> <div>C</div> </div>
What is the likely mistake?
Solution
Step 1: Analyze the class used
The container usesjustify-center, which centers items but does not add space between them.Step 2: Correct class for spacing
To add equal space between items,justify-betweenshould be used instead.Final Answer:
Using justify-center instead of justify-between -> Option BQuick Check:
Centering ≠ spacing between items [OK]
- Confusing justify-center with justify-between
- Adding unnecessary classes like inline-block
- Thinking flex-row is missing when flex defaults to row
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-aroundadds equal space around each item, including edges, unlikejustify-betweenwhich has no edge space.Final Answer:
justify-around -> Option CQuick Check:
Space around items and edges = justify-around [OK]
- Choosing justify-between which lacks edge space
- Using justify-center which centers items only
- Assuming justify-start spaces items evenly
Ready to prove it?
Pass the test and this pattern moves unknown
