Align items helps you control how things line up inside a box. It makes your page look neat and organized.
Align items in CSS
.container { display: flex; align-items: value; }
The align-items property works only if the container uses display: flex or display: grid.
The value can be flex-start, flex-end, center, baseline, or stretch.
.container { display: flex; align-items: center; }
.container { display: flex; align-items: flex-start; }
.container { display: flex; align-items: flex-end; }
.container { display: flex; align-items: stretch; }
This example shows three colored boxes inside a container. The container uses align-items: center to line up the boxes vertically in the middle, even though they have different heights.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> <title>Align Items Example</title> <style> .container { display: flex; height: 10rem; border: 2px solid #333; align-items: center; background-color: #f0f0f0; gap: 1rem; padding: 1rem; } .box { width: 4rem; background-color: #4a90e2; color: white; display: flex; justify-content: center; align-items: center; font-weight: bold; border-radius: 0.5rem; } </style> </head> <body> <main> <section class="container" aria-label="Example of align-items center"> <div class="box">A</div> <div class="box" style="height: 6rem;">B</div> <div class="box" style="height: 3rem;">C</div> </section> </main> </body> </html>
If you want to align items horizontally, use justify-content instead.
Using align-items: stretch makes items fill the container's height if they don't have a fixed height.
Try changing the align-items value in the example to see how the boxes move.
Align items controls vertical alignment inside flex or grid containers.
Common values are center, flex-start, flex-end, and stretch.
It helps make layouts look neat and balanced.