Discover how a single CSS property can save you hours of tedious spacing work!
Why Justify content (main axis) in Tailwind? - Purpose & Use Cases
Imagine you are arranging books on a shelf and want them spaced evenly or pushed to one side, but you have to place each book by hand, guessing the space between them.
If you try to space items manually, you spend a lot of time measuring and adjusting. If you add or remove a book, you must redo all the spacing, which is tiring and error-prone.
Using justify-content on the main axis automatically arranges items with consistent spacing or alignment, so you don't have to guess or adjust manually.
<div style="display:flex;"> <div style="margin-right:20px;">Book 1</div> <div style="margin-right:20px;">Book 2</div> <div>Book 3</div> </div>
<div class="flex justify-between"> <div>Book 1</div> <div>Book 2</div> <div>Book 3</div> </div>
You can easily control how items line up or spread out along a row or column, making layouts neat and flexible without extra work.
On a website header, you want the logo on the left and navigation links spaced evenly across the top. Justify content helps place them perfectly without manual spacing.
Manual spacing is slow and breaks easily when content changes.
Justify content aligns or spaces items automatically along the main axis.
Tailwind classes like justify-between make this simple and responsive.
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
