Skip to main content

justify-items Property in CSS Grid Layouts

justify-items specify the default justify-self value for all the grid items.

The justify-items property accepts the following values:

  • stretch
  • start
  • center
  • end

Let's discuss the four values.

Buy your CSS Flexbox Explained Visually book on Amazon

What Is justify-items: stretch in CSS Grid?

stretch is justify-items' default value. It stretches the grid container's items to fill their individual cells' row (inline) axis.

Illustration of justify-items' stretch value in CSS Grid

Here's an example:

section {
display: grid;
justify-items: stretch;
grid-template-columns: 1fr 1fr;
background-color: orange;
margin: 10px;
}

div {
border: 1px solid black;
background-color: purple;
color: white;
padding: 10px;
border-radius: 5px;
}

Try it on StackBlitz

The snippet above used the stretch value to stretch the grid items to fill their individual cells' row axis.

What Is justify-items: start in CSS Grid?

start positions a grid container's items with the row-start edge of their individual cells' row axis.

Illustration of justify-items' start value in CSS Grid

Here's an example:

section {
display: grid;
justify-items: start;
grid-template-columns: 1fr 1fr;
background-color: orange;
margin: 10px;
}

div {
border: 1px solid black;
background-color: purple;
color: white;
padding: 10px;
border-radius: 5px;
}

Try it on StackBlitz

The snippet above used the start value to position the grid items to their individual cells' row-start edge.

What Is justify-items: center in CSS Grid?

center positions a grid container's items to the center of their individual cells' row axis.

Illustration of justify-items' center value in CSS Grid

Here's an example:

section {
display: grid;
justify-items: center;
grid-template-columns: 1fr 1fr;
background-color: orange;
margin: 10px;
}

div {
border: 1px solid black;
background-color: purple;
color: white;
padding: 10px;
border-radius: 5px;
}

Try it on StackBlitz

The snippet above used the center value to position the grid items to the center of their individual cells' row axis.

What Is justify-items: end in CSS Grid?

end positions a grid container's items with the row-end edge of their individual cells' row axis.

Illustration of justify-items' end value in CSS Grid

Here's an example:

section {
display: grid;
justify-items: end;
grid-template-columns: 1fr 1fr;
background-color: orange;
margin: 10px;
}

div {
border: 1px solid black;
background-color: purple;
color: white;
padding: 10px;
border-radius: 5px;
}

Try it on StackBlitz

The snippet above used the end value to position the grid items to their individual cells' row-end edge.

Buy your CSS Flexbox Explained Visually book on Amazon

Overview

This article discussed what a CSS justify-items property is. We also discussed its values.

Find all your favorite books at booksamillion.com.