Currently Empty: ₹0.00
CSS Align Items
CSS CODES & EXAMPLES
CSS Align Items
Learn how the CSS align-items property controls
the alignment of flex items across the cross axis of a
flex container.
01
What is Align Items?
Control alignment on the cross axis
The align-items property defines how flex items
are aligned on the cross axis of a flex
container.
Remember:
With
flex-direction: row, the cross axis is
vertical. With flex-direction: column, the
cross axis is horizontal.
02
Syntax
Basic CSS syntaxalign-items.css
.container {
display: flex;
align-items: center;
}03
align-items: stretch
Default value
stretch makes flex items stretch across the
cross axis when their cross-size is not explicitly defined.
stretch.css
.container {
display: flex;
align-items: stretch;
}1
2
3
04
align-items: flex-start
Align items at the beginning
flex-start places the flex items at the beginning
of the cross axis.
flex-start.css
.container {
display: flex;
align-items: flex-start;
}1
2
3
05
align-items: flex-end
Align items at the end
flex-end moves the flex items to the end of the
cross axis.
flex-end.css
.container {
display: flex;
align-items: flex-end;
}1
2
3
06
align-items: center
Center items on the cross axis
center places the flex items in the center of
the cross axis. This is one of the most commonly used
Flexbox values.
center.css
.container {
display: flex;
align-items: center;
}1
2
3
07
align-items: baseline
Align text baselines
baseline aligns flex items according to their
text baselines. It is particularly useful when items contain
text with different font sizes.
baseline.css
.container {
display: flex;
align-items: baseline;
}Small
Large
Medium
08
Align Items Comparison
See the difference visuallyflex-start
1
2
3
center
1
2
3
flex-end
1
2
3
stretch
1
2
3
09
Align Items with Row
Vertical cross axis
row.css
.container {
display: flex;
flex-direction: row;
align-items: center;
}HTML
CSS
JavaScript
With flex-direction: row, the cross axis is
vertical. Therefore, align-items: center
vertically centers the items.
10
Align Items with Column
Horizontal cross axis
column.css
.container {
display: flex;
flex-direction: column;
align-items: center;
}HTML
CSS
JavaScript
When the direction is column, the cross axis
becomes horizontal. Therefore, align-items: center
centers the items horizontally.
11
Justify Content vs Align Items
Understand the two important Flexbox properties| Property | Controls | Row Direction | Column Direction |
|---|---|---|---|
justify-content | Main axis | Horizontal | Vertical |
align-items | Cross axis | Vertical | Horizontal |
12
Practical Website Example
Center content inside a card
A common website layout uses
align-items: center to vertically align an
icon, title, and button inside a horizontal card.
card.css
.course-card {
display: flex;
align-items: center;
gap: 20px;
}
.course-icon {
width: 70px;
height: 70px;
}Web Designing Course
Learn HTML, CSS and responsive website design.
13
Quick Reference
Common align-items valuesstretchStretches items across the cross axis.
flex-startMoves items to the start of the cross axis.
flex-endMoves items to the end of the cross axis.
centerCenters items on the cross axis.
baselineAligns items according to their text baseline.
14
Important Points
Remember these Flexbox rules
✓
align-items controls the cross axis.
✓
Its default value is stretch.
✓
In a row layout, the cross axis is vertical.
✓
In a column layout, the cross axis is horizontal.
15
Practice Task
Create a perfectly aligned course card🎯 Build a Course Information Card
Create a horizontal course card containing an icon, course information and an enrollment button.
-
Use
display: flex; -
Use
align-items: center; -
Add
gap: 20px; - Add a course icon on the left.
- Add course title and description.
- Add an action button on the right.
16
CSS Align Items Live Example
Run the practical exampleLIVE PREVIEW



