Justify-Content and Align-Items
Distribute items along the main axis and cross axis using justify-content and align-items.
Justify-Content and Align-Items is a free CSS Academy lesson on CoddyKit. This is lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the CSS Academy learning path, and your progress syncs across the web and the CoddyKit app. The CSS Academy course includes 4 lessons in total.
Two Key Alignment Properties
The two most used flex alignment properties are:
justify-content— aligns items along the main axisalign-items— aligns items along the cross axis
justify-content: flex-start
flex-start (default) packs items toward the start of the main axis. In row direction, items align to the left.
<nav class="nav">
<a href="#">Home</a>
<a href="#">About</a>
<a href="#">Contact</a>
</nav>
justify-content: center
Centers items along the main axis. The classic horizontal centering technique with flexbox.
<div class="hero">
<button>Get Started</button>
</div>
justify-content: flex-end
Packs items toward the end of the main axis (right side in row direction).
<div class="header">
<button>Sign In</button>
<button>Sign Up</button>
</div>
justify-content: space-between
Distributes items with equal space between them. First item is at start, last item is at end — no space at edges.
<nav class="nav">
<div class="logo">Logo</div>
<div class="links">
<a href="#">Home</a>
<a href="#">About</a>
</div>
</nav>
justify-content: space-around
Places equal space around each item. Edge items get half the space of inner gaps. Visually, the edges have half as much padding as between items.
justify-content: space-evenly
All gaps (including edges) are equal. Unlike space-around, edge padding equals inter-item gaps.
<div class="toolbar">
<button>Bold</button>
<button>Italic</button>
<button>Underline</button>
</div>
align-items: stretch (Default)
stretch (default) makes all flex items on the cross axis fill the container's cross size. Items in a row container all become the same height.
<div class="row">
<div>Short</div>
<div>Taller content<br>spanning<br>multiple lines</div>
<div>Mid</div>
</div>
align-items: center
Centers items on the cross axis. In a row container, this vertically centers items. The classic vertical centering solution.
<div class="card">
<span>👤</span>
<span>Jane Doe</span>
</div>
align-items: flex-start and flex-end
flex-start aligns items to the cross-start edge (top in row). flex-end aligns to the cross-end edge (bottom in row).
<nav class="nav">
<div>Short</div>
<div>Taller<br>nav<br>item</div>
</nav>
align-items: baseline
Aligns items so their text baselines align. Useful when items have different font sizes but should look visually aligned.
<nav class="breadcrumb">
<span style="font-size:12px">Home</span>
<span style="font-size:24px">Products</span>
<span style="font-size:16px">Item</span>
</nav>
Quick Check
Which combination perfectly centers a flex item both horizontally and vertically within its container?
Recap
justify-content distributes items along the main axis with values like flex-start, center, space-between. align-items positions items on the cross axis with stretch, center, flex-start. Together they control both axes of alignment.
Learn CSS with an AI tutor — free
Write and run real code in your browser, get instant help from a 24/7 AI tutor, and pick up where you left off on the web or in the app.
- Courses
- 40
- Lessons
- 159
Frequently Asked Questions
Is the “Justify-Content and Align-Items” lesson free?
Yes — the full text of “Justify-Content and Align-Items” is free to read here on the web. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the CSS Academy course, upgrade to CoddyKit PRO. The CSS Academy course includes 4 lessons in total.
What will I learn in “Justify-Content and Align-Items”?
Distribute items along the main axis and cross axis using justify-content and align-items. You practise CSS Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start CSS Academy?
No prior experience is required. CSS Academy on CoddyKit is structured for beginners through advanced learners, so you can start here or from the beginning and move at your own pace. This is lesson 2 of 4.
How long does the “Justify-Content and Align-Items” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this CSS Academy lesson?
Yes. Every CSS Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Display Flex and Flex Direction
- Justify-Content and Align-Items
- Flex Wrap and Align-Content
- Flex Grow Shrink and Basis