Currently Empty: ₹0.00
CSS Justify Content
CSS CODES & EXAMPLES
CSS Justify Content
Learn how the CSS justify-content property
controls the alignment and distribution of flex items along
the main axis.
01
What is Justify Content?
Control the main-axis alignment of flex items
The justify-content property defines how flex
items are positioned and how extra space is distributed
along the main axis of a flex container.
Remember:
justify-content works along the main axis.
With flex-direction: row, the main axis is
horizontal. With flex-direction: column,
it becomes vertical.
02
Syntax
Basic CSS syntax
justify-content.css
.container {
display: flex;
justify-content: center;
}
03
justify-content: flex-start
Items are placed at the beginning
flex-start places the flex items at the beginning
of the main axis. This is the default behavior.
flex-start.css
.container {
display: flex;
justify-content: flex-start;
}1
2
3
04
justify-content: flex-end
Items are placed at the end
flex-end moves the flex items to the end of
the main axis.
flex-end.css
.container {
display: flex;
justify-content: flex-end;
}1
2
3
05
justify-content: center
Center items along the main axis
center places all flex items in the center of
the main axis.
center.css
.container {
display: flex;
justify-content: center;
}1
2
3
06
justify-content: space-between
Equal space between items
space-between places the first item at the
beginning and the last item at the end. The remaining space
is distributed equally between the items.
space-between.css
.container {
display: flex;
justify-content: space-between;
}1
2
3
07
justify-content: space-around
Space around each item
space-around gives each flex item equal space
around it. The space at the edges is half the space between
adjacent items.
space-around.css
.container {
display: flex;
justify-content: space-around;
}1
2
3
08
justify-content: space-evenly
Exactly equal spacing
space-evenly distributes the available space
equally between all items and the container edges.
space-evenly.css
.container {
display: flex;
justify-content: space-evenly;
}1
2
3
09
Justify Content Comparison
See the difference between common valuesflex-start
1
2
3
center
1
2
3
flex-end
1
2
3
space-between
1
2
3
space-around
1
2
3
space-evenly
1
2
3
10
Justify Content with Row
Horizontal main axis
row.css
.container {
display: flex;
flex-direction: row;
justify-content: center;
}HTML
CSS
JS
Because the direction is row, the main axis is
horizontal. Therefore justify-content: center
centers the items horizontally.
11
Justify Content with Column
Vertical main axis
column.css
.container {
display: flex;
flex-direction: column;
justify-content: space-between;
}TOP
CENTER
BOTTOM
When flex-direction: column is used, the main
axis becomes vertical. Therefore, justify-content
controls vertical distribution.
12
Practical Website Example
Navigation bar using justify-content
A website header can use justify-content to
position a logo and navigation links.
navbar.css
.navbar {
display: flex;
justify-content: space-between;
align-items: center;
}
.nav-links {
display: flex;
gap: 20px;
}
13
Quick Reference
Important values at a glance| Value | Purpose |
|---|---|
flex-start | Items at the beginning of the main axis. |
flex-end | Items at the end of the main axis. |
center | Items centered along the main axis. |
space-between | Equal space between items. |
space-around | Equal space around items. |
space-evenly | Equal space between items and edges. |
14
Practice Task
Create a professional navigation bar🎯 Build a Flexbox Header
Create a navigation bar containing a website logo and four navigation links.
- Use
display: flex; - Use
justify-content: space-between; - Use
align-items: center; - Add spacing between navigation links.
- Make the layout responsive.
15
CSS Justify Content Live Example
Run and experiment with the codeLIVE PREVIEW



