
- 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-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.
Syntax
align-items: normal | stretch | center | flex-start | flex-end | baseline | initial | inherit;
Property Values
Value | Description |
---|---|
normal | It behaves like 'stretch' for flexbox and grid items, or 'start' for grid items with a defined block size.Default. |
stretch | The items are stretched to fit the container. |
center | The items are placed at the center position of the container. |
flex-start | The items are placed at the beginning position of the container. |
flex-end | The items are placed at the ending position of the container. |
start | The items are placed at the beginning of their individual grid cells, in the block direction. |
end | The items are placed at the end of the their individual grid cells, in the block direction. |
baseline | The items are placed at the baseline position of the container. |
initial | This sets the property to its default value. |
inherit | This inherits the property from the parent element. |
Examples of CSS Align Items Property
The following examples describe the align-items property with different values.
Stretched Flex Items
To stretch the flex items vertically to fill the entire space of the flex container, we use the stretch value. In the following example, stretch value has been used.
Example
<!DOCTYPE html> <html> <head> <style> .flex-container { display: flex; align-items: stretch; border: 1px dashed black; height: 200px; gap: 10px; } .flex-container div { background-color: grey; border: 2px solid black; } </style> </head> <body> <h2>CSS align-items 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> </body> </html>
Centered Flex Items
To align the flex items at the center of the cross axis of a container, we use the center value. In the following example, center value has been used.
Example
<!DOCTYPE html> <html> <head> <style> .flex-container { display: flex; align-items: center; border: 1px dashed black; height: 200px; gap: 10px; } .flex-container div { background-color: grey; border: 2px solid black; } </style> </head> <body> <h2>CSS align-items 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> </body> </html>
Flex Items at Starting Position
To align the flex items at the start of the cross axis of a container, we use the flex-start value. In the following example, flex-start value has been used.
Example
<!DOCTYPE html> <html> <head> <style> .flex-container { display: flex; align-items: flex-start; border: 1px dashed black; height: 200px; gap: 10px; } .flex-container div { background-color: grey; border: 2px solid black; } </style> </head> <body> <h2>CSS align-items 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> </body> </html>
Flex Items at the Ending Position
To align the flex items at the end of the cross axis of a container, we use the flex-end value. In the following example, flex-end value has been used. −
Example
<!DOCTYPE html> <html> <head> <style> .flex-container { display: flex; align-items: flex-end; border: 1px dashed black; height: 200px; gap: 10px; } .flex-container div { background-color: grey; border: 2px solid black; } </style> </head> <body> <h2>CSS align-items 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> </body> </html>
Flex or Non-flex Items at the Starting Position
To align the flex and non-flex items at the start of the cross axis of a container, we use the start value. In the following example, grid display has been used with start value of align-items.
Example
<!DOCTYPE html> <html> <head> <style> .grid-container { display: grid; grid-template-columns: repeat(3, 1fr); grid-gap: 10px; align-items: start; border: 1px dashed black; height: 200px; } .grid-item { background-color: grey; border: 2px solid black; } </style> </head> <body> <h2>CSS align-items property</h2> <div class="grid-container"> <div class="grid-item">Item 1</div> <div class="grid-item">Item 2</div> <div class="grid-item">Item 3</div> <div class="grid-item">Item 4</div> <div class="grid-item">Item 5</div> <div class="grid-item">Item 6</div> </div> </body> </html>
Flex or Non-flex Items at the Ending Position
To align the flex and non-flex items at the end of the cross axis of a container, we use the end value. In the following example, grid display has been used with end value of align-it.
Example
<!DOCTYPE html> <html> <head> <style> .grid-container { display: grid; grid-template-columns: repeat(3, 1fr); grid-gap: 10px; align-items: end; border: 1px dashed black; height: 200px; } .grid-item { background-color: grey; border: 2px solid black; } </style> </head> <body> <h2>CSS align-items property</h2> <div class="grid-container"> <div class="grid-item">Item 1</div> <div class="grid-item">Item 2</div> <div class="grid-item">Item 3</div> <div class="grid-item">Item 4</div> <div class="grid-item">Item 5</div> <div class="grid-item">Item 6</div> </div> </body> </html>
Flex Items at Baseline
To aligns flex items along their baselines, we use the baseline value. In the following example, baseline value has been used.
Example
<!DOCTYPE html> <html> <head> <style> .flex-container { display: flex; align-items: baseline; border: 1px dashed black; height: 200px; gap: 10px; } .flex-container div { background-color: grey; border: 2px solid black; } </style> </head> <body> <h2>CSS align-items 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> </body> </html>
Stretched Flex or Non-Flex Items by Normal
To align the flex or non-flex items to stretch vertically to fill the container, we use the normal value. In the following example, normal value has been used with non-flex items.
Example
<!DOCTYPE html> <html> <head> <style> .grid-container { display: grid; grid-template-columns: repeat(3, 1fr); grid-gap: 10px; align-items: stretched; border: 1px dashed black; height: 200px; } .grid-item { background-color: grey; border: 2px solid black; } </style> </head> <body> <h2>CSS align-items property</h2> <div class="grid-container"> <div class="grid-item">Item 1</div> <div class="grid-item">Item 2</div> <div class="grid-item">Item 3</div> <div class="grid-item">Item 4</div> <div class="grid-item">Item 5</div> <div class="grid-item">Item 6</div> </div> </body> </html>
Supported Browsers
Property | ![]() |
![]() |
![]() |
![]() |
![]() |
---|---|---|---|---|---|
align-items | 57.0 | 16.0 | 52.0 | 10.1 | 44.0 |