
- CSS - Home
- CSS - Roadmap
- CSS - Introduction
- CSS - Syntax
- CSS - Inclusion
- CSS - Types
- CSS - Measurement Units
- CSS - Selectors
- CSS - Colors
- CSS - Backgrounds
- CSS - Fonts
- CSS - Text
- CSS - Images
- CSS - Links
- CSS - Tables
- CSS - Borders
- CSS - Border Block
- CSS - Border Inline
- CSS - Margins
- CSS - Lists
- CSS - Padding
- CSS - Cursor
- CSS - Outlines
- CSS - Dimension
- CSS - Scrollbars
- CSS - Inline Block
- CSS - Dropdowns
- CSS - Visibility
- CSS - Overflow
- CSS - Clearfix
- CSS - Float
- CSS - Arrows
- CSS - Resize
- CSS - Quotes
- CSS - Order
- CSS - Position
- CSS - Hyphens
- CSS - Hover
- CSS - Display
- CSS - Focus
- CSS - Zoom
- CSS - Translate
- CSS - Height
- CSS - Hyphenate Character
- CSS - Width
- CSS - Opacity
- CSS - Z-Index
- CSS - Bottom
- CSS - Navbar
- CSS - Overlay
- CSS - Forms
- CSS - Align
- CSS - Icons
- CSS - Image Gallery
- CSS - Comments
- CSS - Loaders
- CSS - Attr Selectors
- CSS - Combinators
- CSS - Root
- CSS - Box Model
- CSS - Counters
- CSS - Clip
- CSS - Writing Mode
- CSS - Unicode-bidi
- CSS - min-content
- CSS - All
- CSS - Inset
- CSS - Isolation
- CSS - Overscroll
- CSS - Justify Items
- CSS - Justify Self
- CSS - Tab Size
- CSS - Pointer Events
- CSS - Place Content
- CSS - Place Items
- CSS - Place Self
- CSS - Max Block Size
- CSS - Min Block Size
- CSS - Mix Blend Mode
- CSS - Max Inline Size
- CSS - Min Inline Size
- CSS - Offset
- CSS - Accent Color
- CSS - User Select
- CSS - Cascading
- CSS - Universal Selectors
- CSS - ID Selectors
- CSS - Group Selectors
- CSS - Class Selectors
- CSS - Child Selectors
- CSS - Element Selectors
- CSS - Descendant Selectors
- CSS - General Sibling Selectors
- CSS - Adjacent Sibling Selectors
- CSS Advanced
- CSS - Grid
- CSS - Grid Layout
- CSS - Flexbox
- CSS - Visibility
- CSS - Positioning
- CSS - Layers
- CSS - Pseudo Classes
- CSS - Pseudo Elements
- CSS - @ Rules
- CSS - Text Effects
- CSS - Paged Media
- CSS - Printing
- CSS - Layouts
- CSS - Validations
- CSS - Image Sprites
- CSS - Important
- CSS - Data Types
- CSS3 Advanced Features
- CSS - Rounded Corner
- CSS - Border Images
- CSS - Multi Background
- CSS - Color
- CSS - Gradients
- CSS - Box Shadow
- CSS - Box Decoration Break
- CSS - Caret Color
- CSS - Text Shadow
- CSS - Text
- CSS - 2d transform
- CSS - 3d transform
- CSS - Transition
- CSS - Animation
- CSS - Multi columns
- CSS - Box Sizing
- CSS - Tooltips
- CSS - Buttons
- CSS - Pagination
- CSS - Variables
- CSS - Media Queries
- CSS - Functions
- CSS - Math Functions
- CSS - Masking
- CSS - Shapes
- CSS - Style Images
- CSS - Specificity
- CSS - Custom Properties
- CSS Responsive
- CSS RWD - Introduction
- CSS RWD - Viewport
- CSS RWD - Grid View
- CSS RWD - Media Queries
- CSS RWD - Images
- CSS RWD - Videos
- CSS RWD - Frameworks
- CSS References
- CSS Interview Questions
- CSS Online Quiz
- CSS Online Test
- CSS Mock Test
- CSS - Quick Guide
- CSS - Cheatsheet
- CSS - Properties References
- CSS - Functions References
- CSS - Color References
- CSS - Web Browser References
- CSS - Web Safe Fonts
- CSS - Units
- CSS - Animation
- CSS Resources
- CSS - Useful Resources
- CSS - Discussion
CSS - justify-content Property
CSS justify-content property determines the alignment and allocation of space between content items along the main axis of a flex container or the inline axis of a grid container. In the case of flex container, the direction of main axis is determined by flex-direction and the direction perpendicular to main-axis is the cross-axis.
Syntax
Positional Alignment
justify-content: flex-start | flex-end | center | space-between | space-around | space-evenly | initial | inherit;
Property Values
Value | Description |
---|---|
flex-start | The items are positioned at the start of the container. Default. |
flex-end | The items are positioned at the end of the container. |
center | The items are positioned at the center of the container. |
space-between | The items in the container have space between them. |
space-around | The items in the container have space before, between and after them. |
space-evenly | The items in the container have equal space around them. |
initial | It sets the property to its default value. |
inherit | It inherits the property from the parent element. |
Examples of CSS Justify Content Property
The following examples explain the justify-content property with different values.
Justify Content Property with Flex Start Value
To position the items at the start of a flex container along the main-axis, we use the flex-start value. This is shown in the following example.
Example
<!DOCTYPE html> <html> <head> <style> .container { display: flex; justify-content: flex-start; gap: 10px; border: 2px solid black; height: 200px; padding: 5px; } .container>div { background-color: lightblue; text-align: center; bordeR: 2px solid blue; color: white; padding: 15px; height: 20px; width: 60px; } </style> </head> <body> <h2> CSS justify-content property </h2> <h4> justify-content: flex-start; display:flex </h4> <div class="container"> <div> Item-1 </div> <div> Item-2 </div> <div> Item-3 </div> </div> </body> </html>
Justify Content Property with Flex End Value
To position the items at the end of a flex container along the main-axis, we use the flex-end value. This is shown in the following example.
Example
<!DOCTYPE html> <html> <head> <style> .container { display: flex; justify-content: flex-end; gap: 10px; border: 2px solid black; height: 200px; padding: 5px; } .container>div { background-color: lightblue; text-align: center; bordeR: 2px solid blue; color: white; padding: 15px; height: 20px; width: 60px; } </style> </head> <body> <h2> CSS justify-content property </h2> <h4> justify-content: flex-end; display:flex </h4> <div class="container"> <div> Item-1 </div> <div> Item-2 </div> <div> Item-3 </div> </div> </body> </html>
Justify Content Property with Center Value
To position the items at the center of a flex container along the main-axis, we use the center value. This is shown in the following example.
Example
<!DOCTYPE html> <html> <head> <style> .container { display: flex; justify-content: center; gap: 10px; border: 2px solid black; height: 200px; padding: 5px; } .container>div { background-color: lightblue; text-align: center; bordeR: 2px solid blue; color: white; padding: 15px; height: 20px; width: 60px; } </style> </head> <body> <h2> CSS justify-content property </h2> <h4> justify-content: center; display:flex </h4> <div class="container"> <div> Item-1 </div> <div> Item-2 </div> <div> Item-3 </div> </div> </body> </html>
Justify Content Property with Space Between Value
To position the items in a flex container along the main-axis such that they have space betweent them, we use the space-between value. This is shown in the following example.
Example
<!DOCTYPE html> <html> <head> <style> .container { display: flex; justify-content: space-between; gap: 10px; border: 2px solid black; height: 200px; padding: 5px; } .container>div { background-color: lightblue; text-align: center; bordeR: 2px solid blue; color: white; padding: 15px; height: 20px; width: 60px; } </style> </head> <body> <h2> CSS justify-content property </h2> <h4> justify-content: space-between; display:flex </h4> <div class="container"> <div> Item-1 </div> <div> Item-2 </div> <div> Item-3 </div> </div> </body> </html>
Justify Content Property with Space Around Value
To position the items in a flex container along the main-axis such that they have space before, after and between them, we use the space-around value. This is shown in the following example.
Example
<!DOCTYPE html> <html> <head> <style> .container { display: flex; justify-content: space-around; gap: 10px; border: 2px solid black; height: 200px; padding: 5px; } .container>div { background-color: lightblue; text-align: center; bordeR: 2px solid blue; color: white; padding: 15px; height: 20px; width: 60px; } </style> </head> <body> <h2> CSS justify-content property </h2> <h4> justify-content: space-around; display:flex </h4> <div class="container"> <div> Item-1 </div> <div> Item-2 </div> <div> Item-3 </div> </div> </body> </html>
Justify Content Property with Space Evenly Value
To position the items in a flex container along the main-axis such that they have equal distribution of space around them, we use the space-evenly value. This is shown in the following example.
Example
<!DOCTYPE html> <html> <head> <style> .container { display: flex; justify-content: space-evenly; gap: 10px; border: 2px solid black; height: 200px; padding: 5px; } .container>div { background-color: lightblue; text-align: center; bordeR: 2px solid blue; color: white; padding: 15px; height: 20px; width: 60px; } </style> </head> <body> <h2> CSS justify-content property </h2> <h4> justify-content: space-evenly; display:flex </h4> <div class="container"> <div> Item-1 </div> <div> Item-2 </div> <div> Item-3 </div> </div> </body> </html>
Justify Content Property with Grid Layout
The justify-content property can also be used with the grid layout to align items in the inline direction. This is shown in the following example.
Example
<!DOCTYPE html> <html> <head> <style> .container { display: grid; justify-content: center; gap: 10px; border: 2px solid black; height: 300px; padding: 5px; } .container>div { background-color: lightblue; text-align: center; bordeR: 2px solid blue; color: white; padding: 15px; height: 30px; width: 80px; } </style> </head> <body> <h2> CSS justify-content property </h2> <h4> justify-content: center; display:grid </h4> <div class="container"> <div> Item-1 </div> <div> Item-2 </div> <div> Item-3 </div> </div> </body> </html>
Supported Browsers
Property | ![]() |
![]() |
![]() |
![]() |
![]() |
---|---|---|---|---|---|
justify-content | 29.0 | 11.0 | 28.0 | 9.0 | 17.0 |