Main Axis Alignment Property

Last updated: 2026-09-13

justify-content Main Axis Alignment Property

The justify-content property sets how flex items are aligned along the main axis and how the space between items and between items and the container edges is distributed. It is the most frequently used alignment property in flexbox and supports left, right, center, space-between, space-around and space-evenly arrangements. The main axis is determined by flex-direction.

Category
Initial Valuenormal
InheritedNo
Applies Toall
Animation Typediscrete
CSS VersionCSS3
StatusStandard

📝 Syntax

justify-content: normal | start | end | flex-start | flex-end | center | left | right | space-between | space-around | space-evenly | stretch;

⚙️ Values

ValueTypeDescription
normal | flex-start | flex-end | center | space-between | space-around | space-evenlyKeywordMain axis alignment

▶ Example

Edit the code below and see the live result in the playground:

🌐 Browser Support

Browser ChromeChrome EdgeEdge FirefoxFirefox SafariSafari OperaOpera
justify-content v29 v12 v28 v9 v17
Supported in all major browsers
Tip: space-between pushes the first and last items flush with the edges and spaces the middle ones evenly; space-around gives every item equal space on both sides, so the edge gaps are half the inner gaps; space-evenly makes all gaps exactly equal.
Important: justify-content acts on the main axis. If flex-direction is column, it controls vertical alignment and you need a defined container height to see any effect.

❓ FAQ

QWhat is the difference between space-between, space-around and space-evenly?
Aspace-between places the first and last items flush with the edges and spaces the middle ones evenly. space-around gives each item equal space on its left and right, so the gaps at the edges are half the gap between two items. space-evenly makes every gap, including the ones at the edges, exactly equal. Pick space-between when the ends should touch the edges and space-evenly when you want the most uniform distribution.
QWhat is the difference between justify-content and text-align: center?
Atext-align: center aligns inline content such as text and inline elements inside a block container; it works at the text level. justify-content: center positions flex items along the main axis; it works at the layout level and also supports distribution modes such as space-between. The two also coexist: a flex container can center its items with justify-content while the text inside each item is still aligned by text-align. Use justify-content for layout and text-align for text.
QWhy doesn’t justify-content: center work?
AThe most common reason is that the container has no leftover space: when the items’ total width equals or exceeds the container width, there is no free space on the main axis to distribute and the centering has nothing to act on. Also, with flex-direction: column you need an explicit height on the container, otherwise the content fills the vertical direction and no space remains. Check the main axis and the container size to find the cause.

📚 Related Tutorials

Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏