Skip to main content

CSS Grid Items - Alignment

Inside its grid cell, an item can be positioned with three properties:

  • justify-self — aligns the item horizontally inside the cell.
  • align-self — aligns the item vertically inside the cell.
  • place-self — shorthand combining align-self and justify-self.

To align every grid item in one go, put justify-items and align-items on the grid container instead.


The CSS justify-self Property

Horizontal (inline direction) placement of a grid item within its cell is handled by the justify-self property.

Tip: On an English page, the inline direction runs left to right and the block direction runs top to bottom.

Its possible values are auto (default), normal, stretch, start, left, center, end, right.

Note: Without free space around the item in the inline direction, this property does nothing.

Example

Here justify-self moves items horizontally inside their own grid cells.

Prompt
Create a CSS Grid layout with 6 items in a 3-column grid. Set item 1 to use justify-self: right and item 6 to use justify-self: center to show horizontal alignment within grid cells.
Output: complete HTML page

The CSS align-self Property

Vertical placement, in the block direction, is what align-self does for a grid item in its cell.

You can set it to auto (default), normal, stretch, start, end, center.

Note: The item must have free space around it in the block direction, or the property changes nothing.

Example

Here align-self moves items vertically inside their own grid cells.

Prompt
Create a CSS Grid layout with 6 items in a 3-column grid with tall rows (about 80px). Set item 1 to use align-self: start and item 6 to use align-self: center to show vertical alignment within grid cells.
Output: complete HTML page

CSS Grid Item Alignment Properties

The properties for grid item alignment at a glance:

  • align-self — aligns an item inside its cell along the block direction.
  • justify-self — aligns an item inside its cell along the inline direction.
  • place-self — shorthand combining align-self and justify-self.