- CSS Tutorial
- CSS - Home
- CSS - Introduction
- CSS - Syntax
- CSS - Selectors
- CSS - Inclusion
- CSS - Measurement Units
- 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 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 Tutorial
- CSS3 - Tutorial
- 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 - Questions and Answers
- CSS - Quick Guide
- CSS - 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
The align-content property of CSS 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).
Possible Values
The align-content property can have following values:
start: Items are aligned to each other against the start edge of the container in the cross-axis.
end: Items are aligned to each other against the end edge of the container in the cross-axis.
flex-start: Aligns the content at the start of the flex container.
flex-end: Aligns the content at the end of the flex container.
center: Aligns the content at the center of the flex container.
normal: Items are aligned at their default position, as if no value is set for align-content.
baseline, first baseline, last baseline:
First baseline, and last baseline are synonym to baseline. First and last refer to the line boxes within the flex items.
These values specify the involvment of first- or last-baseline alignment in the alignment of the content.
start is the fallback alignment for first-baseline and end for last-baseline.
space-between: Distributes the content evenly along the cross-axis, leaving no space before the first line or after the last line.
space-around: Distributes the content evenly along the cross-axis, providing equal space before and after each line.
space-evenly: Distributes the content evenly along the cross-axis, providing equal space before, between, and after each line.
stretch: Stretches the content to fill the container along the cross-axis.
safe: Used with an alignment keyword and when the item overflows the container, causing any loss of data, the alignment is set as per the start value.
unsafe: Used with an alignment keyword and even if the item overflows the container, causing any loss of data, the alignment value passed is honored.
Applies to
Multi-line flex containers.
Syntax
Positional Alignment
align-content: center; align-content: start; align-content: end; align-content: flex-start; align-content: flex-end
Normal Alignment
align-content: normal;
Baseline Alignment
align-content: baseline; align-content: first baseline; align-content: last baseline;
Distributed Alignment
align-content: space-between; align-content: space-around; align-content: space-evenly; align-content: stretch;
CSS align-content- start Value
The following example demonstrates that the align-content: start property aligns the flex items at the start of the cross axis of a flex container −
<html> <head> <style> .flex-container { display: flex; background-color: green; height: 350px; width: 100%; flex-wrap: wrap; align-content: start; } .flex-container div { background-color: yellow; padding: 10px; margin: 5px; width: 90px; height: 50px; } </style> </head> <body> <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>
CSS align-content- end Value
The following example demonstrates that the align-content: end property aligns the flex items at the end of the cross axis of a flex container −
<html> <head> <style> .flex-container { display: flex; background-color: green; height: 350px; width: 100%; flex-wrap: wrap; align-content: end; } .flex-container div { background-color: yellow; padding: 10px; margin: 5px; width: 90px; height: 50px; } </style> </head> <body> <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>
CSS align-content - center Value
The following example demonstrates that the align-content: center property aligns the flex items at the center of the cross axis of a flex container −
<html> <head> <style> .flex-container { display: flex; background-color: green; height: 350px; width: 100%; flex-wrap: wrap; align-content: center; } .flex-container div { background-color: yellow; padding: 10px; margin: 5px; width: 90px; height: 50px; } </style> </head> <body> <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>
CSS align-content - flex-start Value
The following example demonstrates that the align-content: flex-start property aligns the flex items at the start of the flex container −
<html> <head> <style> .flex-container { display: flex; background-color: green; height: 350px; width: 100%; flex-wrap: wrap; align-content: flex-start; } .flex-container div { background-color: yellow; padding: 10px; margin: 5px; width: 90px; height: 50px; } </style> </head> <body> <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>
CSS align-content - flex-end Value
The following example demonstrates that the align-content: flex-end property aligns the flex items at the end of the flex container −
<html> <head> <style> .flex-container { display: flex; background-color: green; height: 350px; width: 100%; flex-wrap: wrap; align-content: flex-end; } .flex-container div { background-color: yellow; padding: 10px; margin: 5px; width: 90px; height: 50px; } </style> </head> <body> <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>
CSS align-content - space-between Value
The following example demonstrates that the align-content: space-between property evenly distributes space between the flex items along the cross axis of a flex container −
<html> <head> <style> .flex-container { display: flex; background-color: green; height: 350px; width: 100%; flex-wrap: wrap; align-content: space-between; } .flex-container div { background-color: yellow; padding: 10px; margin: 5px; width: 90px; height: 50px; } </style> </head> <body> <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>
CSS align-content - space-around Value
The following example demonstrates that align-content: space-around property distributes the flex items within a flex container with equal space around each item −
<html> <head> <style> .flex-container { display: flex; background-color: green; height: 350px; width: 100%; flex-wrap: wrap; align-content: space-around; } .flex-container div { background-color: yellow; padding: 10px; margin: 5px; width: 90px; height: 50px; } </style> </head> <body> <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>
CSS align-content - space-evenly Value
The following example demonstrates that align-content: space-evenly evenly distributes the space around and between the flex items along the cross axis of a flex container −
<html> <head> <style> .flex-container { display: flex; background-color: green; height: 300px; width: 100%; flex-wrap: wrap; align-content: space-evenly; } .flex-container div { background-color: yellow; padding: 10px; margin: 5px; width: 90px; height: 50px; } </style> </head> <body> <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>
CSS align-content - baseline Value
The following example demonstrates that the align-content: baseline property aligns flex items along their baselines of the flex container −
<html> <head> <style> .flex-container { display: flex; background-color: green; height: 350px; width: 100%; flex-wrap: wrap; align-content: baseline; } .flex-container div { background-color: yellow; padding: 10px; margin: 5px; width: 90px; height: 50px; } </style> </head> <body> <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>
CSS align-content - stretch Value
The following example demonstartes that align-content: stretch property stretches the flex items along the cross-axis of the flex container to fill the available space −
<html> <head> <style> .flex-container { display: flex; background-color: green; height: 200px; width: 100%; flex-wrap: wrap; align-content: stretch; } .flex-container div { background-color: yellow; padding: 10px; margin: 5px; width: 90px; } </style> </head> <body> <div class="flex-container"> <div>Flex item 1</div> <div>Flex item 2</div> <div>Flex item 3</div> </div> </body> </html>
To Continue Learning Please Login
Login with Google