The justify-content property aligns flex items or grid tracks along the main axis and controls how extra space is distributed between them. It is one of the most useful flexbox tools for navbars, button rows, and responsive layouts.
01
Main Axis
Horizontal in row flex.
02
Syntax
Keyword values.
03
Flexbox
Align items in a row.
04
CSS Grid
Position grid tracks.
05
Spacing
between, around, evenly.
06
Compare
vs align-items.
Fundamentals
Introduction
The justify-content property in CSS is used in flexbox and grid layouts to align items along the main axis of a container and distribute free space between them.
In a default horizontal flex row, the main axis runs left to right, so justify-content controls horizontal alignment. It is especially useful for navbars, toolbars, card actions, and any layout where you need items spaced predictably.
Definition and Usage
Apply justify-content to a flex or grid container, not to individual items. Use it when you want items grouped at the start, centered, pushed to the ends, or spaced evenly across the available width.
💡
Beginner Tip
Pair justify-content with align-items for full control: justify-content handles the main axis, align-items handles the cross axis.
Foundation
📝 Syntax
Apply justify-content to a flex or grid container:
The grid tracks stay grouped in the center instead of stretching to fill the full container width.
A11y
♿ Accessibility
Preserve logical reading order — visual reordering with flex does not change DOM order for screen readers.
Keep touch targets spaced — space-between nav links still need adequate tap area on mobile.
Test keyboard focus — centered or spaced buttons must remain reachable in a sensible tab order.
Avoid hiding content off-screen — extreme spacing on small screens can push controls out of view.
Use semantic HTML — wrap navigation groups in <nav> with clear labels.
🧠 How justify-content Works
1
Container becomes flex or grid
Items or tracks are laid out along the main axis of the formatting context.
display: flex
2
Free space is calculated
The browser subtracts item sizes from the container size along the main axis.
Layout
3
justify-content distributes space
Keyword values pack, center, or spread items across the remaining main-axis space.
Alignment
=
↔
Balanced main-axis layouts
Toolbars, navbars, and grids align predictably without manual margins on every item.
Compatibility
🖥 Browser Compatibility
justify-content is widely supported in all modern browsers for both flexbox and CSS Grid layouts.
✓ Baseline · Flexbox & Grid
Reliable alignment across browsers
From current Chrome and Safari builds to Firefox and Edge, justify-content is a stable layout tool.
98%Modern browser support
Google Chrome29+ flex · 57+ grid
Full support
Mozilla Firefox28+ flex · 52+ grid
Full support
Apple Safari9+ flex · 10.1+ grid
Full support
Microsoft Edge12+ flex · 16+ grid
Full support
OperaModern versions
Full support
justify-content property98% supported
Bottom line: Use justify-content confidently in modern flexbox and grid layouts.
Wrap Up
🎉 Conclusion
The justify-content property is a versatile tool for aligning and distributing space among items in a flex container or tracks in a grid container. Whether you need centered buttons, a spaced navbar, or evenly distributed icons, it offers clear keyword values for the job.
For beginners, start with center and space-between, then experiment with space-evenly and grid track alignment to see how main-axis spacing changes your layouts.