Trusted answers to developer questions

How to align elements in flex and grids

Get Started With Machine Learning

Learn the fundamentals of Machine Learning with this free course. Future-proof your career by adding ML skills to your toolkit — or prepare to land a job in AI or Data Science.

The CSS align-items property is used to align children elements inside a flex or grid container element. align-items sets the align-self value on all direct children as a group.
In Flexbox, it controls the alignment of items on the Cross Axis. In Grid Layout, it controls the alignment of items on the Block Axis within their grid area.

Syntax

align-items: stretch|center|start|end|baseline|initial|inherit;

Default value: stretch.

For the list of all possible values, check out the official docs.

svg viewer

Implementation

We make the container a Flexbox by setting display: flex. Next, we set the align-items property to the center value, which aligns each div item in the center.

Try experimenting with different values like stretch and start for align-items.

  • HTML
  • CSS (SCSS)

RELATED TAGS

css
alignment
web dev
Copyright ©2024 Educative, Inc. All rights reserved
Did you find this helpful?