- 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-items Property
CSS align-items property collectively sets the align-self value for all immediate children. In Flexbox, it aligns items on the Cross Axis, while in Grid Layout, it aligns items on the Block Axis within their grid area.
Possible Values
The align-items property can have following values:
normal: Based on the layout mode, the effect of normal keyword changes:
Behaves like start on replaced absolutely-positioned boxes, and as stretch in all other absolutely-positioned boxes, when the layout is absolutely-positioned.
Behaves like stretch in static position of absolutely-positioned layouts.
Behaves like stretch for flex items.
Behaves similar to stretch for grid items, except for the boxes which have an aspect ratio or an intrinsic size where it behaves like start.
Does not apply to block-level boxes , and to the table cells.
flex-start: Aligns the cross-start margin edges of the flex items with the cross-start edge of the line.
flex-end: Aligns the cross-end margin edges of the flex items with the cross-end edge of the line.
center: Margins of flex-items' boxes are centered within the line on the cross-axis. when the cross-size of an element is larger than the container, the content overflows equally in both directions.
start: Items are aligned to each other against the start edge of the container, in the appropriate axis.
end: Items are aligned to each other against the end edge of the container, in the appropriate axis.
self-start: Items are aligned to the edge of the alignment container's start side of the item, in the appropriate axis.
self-end: Items are aligned to the edge of the alignment container's end side of the item, in the appropriate axis.
baseline, first baseline, last baseline: Aligns the items such that their baseline is aligned.
stretch: Stretches the flex items such that the cross-size of the item's margin box is the same as the line while respecting width and height constraints.
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
All the HTML elements.
Syntax
Basic Keyword
align-items: normal; align-items: stretch;
Positional Alignment
align-items: center; align-items: start; align-items: end; align-items: flex-start; align-items: flex-end; align-items: self-start; align-items: self-end;
Baseline Alignment
align-items: baseline; align-items: first baseline; align-items: last baseline; align-items: safe center; align-items: unsafe center;
CSS align-items - normal Value
The following example demonstrates that align-items: normal property aligning flex items to stretch vertically to fill the container −
<html> <head> <style> .flex-container { display: flex; align-items: normal; background-color: green; height: 300px; width: 100%; } .flex-container div { background-color: yellow; padding: 10px; margin: 5px; } .flex-item1 { min-height: 40px; } .flex-item2 { min-height: 70px; } .flex-item3 { min-height: 50px; } .flex-item4 { min-height: 90px; } </style> </head> <body> <div class="flex-container"> <div class="flex-item1">Flex item 1</div> <div class="flex-item2">Flex item 2</div> <div class="flex-item3">Flex item 3</div> <div class="flex-item4">Flex item 4</div> </div> </body> </html>
CSS align-items - start Value
The following example demonstrates that align-items: start property aligns the flex items at the start of the cross axis of a container −
<html> <head> <style> .flex-container { display: flex; align-items: start; background-color: green; height: 300px; width: 100%; } .flex-container div { background-color: yellow; padding: 10px; margin: 5px; } .flex-item1 { min-height: 40px; } .flex-item2 { min-height: 70px; } .flex-item3 { min-height: 50px; } .flex-item4 { min-height: 90px; } </style> </head> <body> <div class="flex-container"> <div class="flex-item1">Flex item 1</div> <div class="flex-item2">Flex item 2</div> <div class="flex-item3">Flex item 3</div> <div class="flex-item4">Flex item 4</div> </div> </body> </html>
CSS align-items - end Value
The following example demonstrates that align-items: end property aligns the flex items at the end of the cross axis of a container −
<html> <head> <style> .flex-container { display: flex; align-items: end; background-color: green; height: 300px; width: 100%; } .flex-container div { background-color: yellow; padding: 10px; margin: 5px; } .flex-item1 { min-height: 40px; } .flex-item2 { min-height: 70px; } .flex-item3 { min-height: 50px; } .flex-item4 { min-height: 90px; } </style> </head> <body> <div class="flex-container"> <div class="flex-item1">Flex item 1</div> <div class="flex-item2">Flex item 2</div> <div class="flex-item3">Flex item 3</div> <div class="flex-item4">Flex item 4</div> </div> </body> </html>
CSS align-items - center Value
The following example demonstrates that align-items: center property aligns the flex items at the center of the cross axis of a container −
<html> <head> <style> .flex-container { display: flex; align-items: center; background-color: green; height: 300px; width: 100%; } .flex-container div { background-color: yellow; padding: 10px; margin: 5px; } .flex-item1 { min-height: 40px; } .flex-item2 { min-height: 70px; } .flex-item3 { min-height: 50px; } .flex-item4 { min-height: 90px; } </style> </head> <body> <div class="flex-container"> <div class="flex-item1">Flex item 1</div> <div class="flex-item2">Flex item 2</div> <div class="flex-item3">Flex item 3</div> <div class="flex-item4">Flex item 4</div> </div> </body> </html>
CSS align-items - flex-start Value
The following example demonstrates that align-items: flex-start property aligns the flex items at the start of the cross axis of a container −
<html> <head> <style> .flex-container { display: flex; align-items: flex-start; background-color: green; height: 300px; width: 100%; } .flex-container div { background-color: yellow; padding: 10px; margin: 5px; } .flex-item1 { min-height: 40px; } .flex-item2 { min-height: 70px; } .flex-item3 { min-height: 50px; } .flex-item4 { min-height: 90px; } </style> </head> <body> <div class="flex-container"> <div class="flex-item1">Flex item 1</div> <div class="flex-item2">Flex item 2</div> <div class="flex-item3">Flex item 3</div> <div class="flex-item4">Flex item 4</div> </div> </body> </html>
CSS align-items - flex-end Value
The following example demonstrates that align-items: flex-end property aligns the flex items at the end of the cross axis of a container −
<html> <head> <style> .flex-container { display: flex; align-items: flex-end; background-color: green; height: 300px; width: 100%; } .flex-container div { background-color: yellow; padding: 10px; margin: 5px; } .flex-item1 { min-height: 40px; } .flex-item2 { min-height: 70px; } .flex-item3 { min-height: 50px; } .flex-item4 { min-height: 90px; } </style> </head> <body> <div class="flex-container"> <div class="flex-item1">Flex item 1</div> <div class="flex-item2">Flex item 2</div> <div class="flex-item3">Flex item 3</div> <div class="flex-item4">Flex item 4</div> </div> </body> </html>
CSS align-items - self-start Value
The following example demonstrates that align-items: self-start property aligns the flex items to the top of the flex container −
<html> <head> <style> .flex-container { display: flex; align-items: self-start; background-color: green; height: 300px; width: 100%; } .flex-container div { background-color: yellow; padding: 10px; margin: 5px; } .flex-item1 { min-height: 40px; } .flex-item2 { min-height: 70px; } .flex-item3 { min-height: 50px; } .flex-item4 { min-height: 90px; } </style> </head> <body> <div class="flex-container"> <div class="flex-item1">Flex item 1</div> <div class="flex-item2">Flex item 2</div> <div class="flex-item3">Flex item 3</div> <div class="flex-item4">Flex item 4</div> </div> </body> </html>
CSS align-Items - self-end Value
The following example demonstrates that align-items: self-end property aligns the flex items to the bottom of the flex container −
<html> <head> <style> .flex-container { display: flex; align-items: self-end; background-color: green; height: 300px; width: 100%; } .flex-container div { background-color: yellow; padding: 10px; margin: 5px; } .flex-item1 { min-height: 40px; } .flex-item2 { min-height: 70px; } .flex-item3 { min-height: 50px; } .flex-item4 { min-height: 90px; } </style> </head> <body> <div class="flex-container"> <div class="flex-item1">Flex item 1</div> <div class="flex-item2">Flex item 2</div> <div class="flex-item3">Flex item 3</div> <div class="flex-item4">Flex item 4</div> </div> </body> </html>
CSS align-items - baseline Value
The following example demonstrates that align-items: baseline property aligns flex items along their baselines −
<html> <head> <style> .flex-container { display: flex; align-items: baseline; background-color: green; height: 300px; width: 100%; } .flex-container div { display: flex; background-color: yellow; padding: 10px; margin: 5px; align-items: center; } .flex-item1 { min-height: 40px; } .flex-item2 { min-height: 70px; } .flex-item3 { min-height: 50px; } .flex-item4 { min-height: 90px; } </style> </head> <body> <div class="flex-container"> <div class="flex-item1">Flex item 1</div> <div class="flex-item2">Flex item 2</div> <div class="flex-item3">Flex item 3</div> <div class="flex-item4">Flex item 4</div> </div> </body> </html>
CSS align-items - stretch Value
The following example demonstrates that align-items: stretch property stretch the flex items vertically to fill the entire space of the flex container −
<html> <head> <style> .flex-container { display: flex; align-items: stretch; background-color: green; height: 300px; width: 100%; } .flex-container div { background-color: yellow; padding: 10px; margin: 5px; } .flex-item1 { min-height: 40px; } .flex-item2 { min-height: 70px; } .flex-item3 { min-height: 50px; } .flex-item4 { min-height: 90px; } </style> </head> <body> <div class="flex-container"> <div class="flex-item1">Flex item 1</div> <div class="flex-item2">Flex item 2</div> <div class="flex-item3">Flex item 3</div> <div class="flex-item4">Flex item 4</div> </div> </body> </html>