
- 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 - align-content Property
CSS align-content property is used to align the content of a flex container along the cross-axis or a grid's block axis. It applies to flex containers with multiple lines of flex items.
The property align-content has no effect on single line flex containers (flex-wrap: nowrap).
Syntax
align-content: stretch | center | flex-start | flex-end | space-between | space-around | space-evenly | initial | inherit;
Property Values
Value | Description |
---|---|
stretch | The lines are stretched to take up the remaining space.Default value. |
center | The lines are packed towards the center of the flex container. |
flex-start | The lines are packed towards the start of the flex container. |
flex-end | The lines are packed towards the end of the flex container. |
space-between | The lines are evenly distributed within the flex container. |
space-around | The lines are evenly distributed in the flex container. Half-size spaces on either end. |
space-evenly | The lines are evenly distributed in the flex container. Equal space around them. |
initial | This sets the property to its default value. |
inherit | This inherits the property from the parent element. |
Examples of CSS Align Content Property
The following examples explain the align-content property with different values.
Stretched Flex Items
To stretches the flex items along the cross-axis of the flex container to fill the available space, we use the stretch value. The following example uses the stretch value.
Example
<!DOCTYPE html> <html> <head> <style> .flex-container { display: flex; border:1px solid black; height: 200px; flex-wrap: wrap; align-content: stretch; gap:50px; padding:5px; } .flex-container div { background-color: grey; border:2px solid black; } </style> </head> <body> <h2>CSS align-content property</h2> <div class="flex-container"> <div>Flex item 1</div> <div>Flex item 2</div> <div>Flex item 3</div> </div> </body> </html>
Centering Flex Items
To align the flex items to the center of the cross axis of a flex container, we use the center value. The following example shows uses the center value.
Example
<!DOCTYPE html> <html> <head> <style> .flex-container { display: flex; border: 1px solid black; height: 350px; flex-wrap: wrap; align-content: center; gap:10px; } .flex-container div { background-color: grey; border:2px solid black; } </style> </head> <body> <h2>CSS align-content property</h2> <div class="flex-container"> <div>Flex item 1</div> <div>Flex item 2</div> <div>Flex item 3</div> <div>Flex item 4</div> <div>Flex item 5</div> <div>Flex item 6</div> <div>Flex item 7</div> </div> </body> </html>
Flex Items to the Start of Flex Container
To align the flex items to the start of the cross axis of a flex container, we use the start value. The following example shows uses the start value.
Example
<!DOCTYPE html> <html> <head> <style> .flex-container { display: flex; border:1px solid black; height: 350px; flex-wrap: wrap; align-content: flex-start; gap:10px; } .flex-container div { background-color: grey; border:2px solid black; } </style> </head> <body> <h2>CSS align-content property</h2> <div class="flex-container"> <div>Flex item 1</div> <div>Flex item 2</div> <div>Flex item 3</div> <div>Flex item 4</div> <div>Flex item 5</div> <div>Flex item 6</div> <div>Flex item 7</div> </div> </body> </html>
Flex Items to the End of Flex Container
To align the flex items to the end of the cross axis of a flex container, we use the end value. The following example shows uses the end value.
Example
<!DOCTYPE html> <html> <head> <style> .flex-container { display: flex; border:1px solid black; height: 350px; flex-wrap: wrap; align-content: flex-end; gap:10px; } .flex-container div { background-color: grey; border:2px solid black; } </style> </head> <body> <h2>CSS align-content property</h2> <div class="flex-container"> <div>Flex item 1</div> <div>Flex item 2</div> <div>Flex item 3</div> <div>Flex item 4</div> <div>Flex item 5</div> <div>Flex item 6</div> <div>Flex item 7</div> </div> </body> </html>
Space Between Flex Items
To evenly distribute space between the flex items along the cross axis of a flex container, we use the space between value. The following example uses space between value.
Example
<!DOCTYPE html> <html> <head> <style> .flex-container { display: flex; border:1px solid black; height: 350px; flex-wrap: wrap; align-content: space-between; gap:10px; } .flex-container div { background-color: grey; border:2px solid black; } </style> </head> <body> <h2>CSS align-content property</h2> <div class="flex-container"> <div>Flex item 1</div> <div>Flex item 2</div> <div>Flex item 3</div> <div>Flex item 4</div> <div>Flex item 5</div> <div>Flex item 6</div> <div>Flex item 7</div> </div> </body> </html>
Space Around Flex Items
To distributee the flex items within a flex container with equal space around each item, we use the space around value. The following example uses the space around value.
Example
<!DOCTYPE html> <html> <head> <style> .flex-container { display: flex; border:1px solid black; height: 350px; flex-wrap: wrap; align-content: space-around; gap:10px; } .flex-container div { background-color: grey; border:2px solid black; } </style> </head> <body> <h2>CSS align-content property</h2> <div class="flex-container"> <div>Flex item 1</div> <div>Flex item 2</div> <div>Flex item 3</div> <div>Flex item 4</div> <div>Flex item 5</div> <div>Flex item 6</div> <div>Flex item 7</div> </div> </body> </html>
Even Space Between and Around Flex Items
To evenly distributes the space around and between the flex items along the cross axis of a flex container, we use the space evenly value. The following example uses the space evenly value.
Example
<!DOCTYPE html> <html> <head> <style> .flex-container { display: flex; border:1px solid black; height: 300px; flex-wrap: wrap; align-content: space-evenly; gap:10px; } .flex-container div { background-color: grey; border:2px solid black; } </style> </head> <body> <h2>CSS align-content property</h2> <div class="flex-container"> <div>Flex item 1</div> <div>Flex item 2</div> <div>Flex item 3</div> <div>Flex item 4</div> <div>Flex item 5</div> <div>Flex item 6</div> </div> </body> </html>
Supported Browsers
Property | ![]() |
![]() |
![]() |
![]() |
![]() |
---|---|---|---|---|---|
align-content | 57.0 | 16.0 | 52.0 | 10.1 | 44.0 |