CSS justify-items Property

The CSS justify-items property sets the default inline-axis alignment of items within their individual grid areas or other supported alignment containers.

It is most commonly used in CSS Grid to position items at the start, center, or end of their grid areas, or to stretch them across the available inline space. Unlike justify-content, which aligns the grid tracks as a group, justify-items controls the alignment of the items inside those tracks.

justify-items Syntax

The justify-items property accepts alignment keywords that determine how items are positioned within their available inline-axis space.

Basic Syntax

selector {
  justify-items: center;
}

Common Alignment Values

.container {
  justify-items: normal;
}
.container {
  justify-items: start;
}
.container {
  justify-items: end;
}
.container {
  justify-items: center;
}
.container {
  justify-items: stretch;
}

Self-Relative Alignment

.container {
  justify-items: self-start;
}
.container {
  justify-items: self-end;
}

Physical Alignment

.container {
  justify-items: left;
}
.container {
  justify-items: right;
}

Overflow Alignment

.container {
  justify-items: safe center;
}
.container {
  justify-items: unsafe center;
}

Legacy Alignment

.container {
  justify-items: legacy left;
}
.container {
  justify-items: legacy right;
}
.container {
  justify-items: legacy center;
}

CSS-Wide Keywords

.container {
  justify-items: initial;
}
.container {
  justify-items: inherit;
}
.container {
  justify-items: unset;
}
.container {
  justify-items: revert;
}
.container {
  justify-items: revert-layer;
}

The initial value is normal. In Grid, this generally produces stretching behavior for eligible items, with exceptions for certain intrinsic sizing situations.

Property Values

The following values determine how items are aligned within their layout areas.

Value Description
normal Uses the default alignment behavior for the layout mode and item sizing rules.
start Aligns items toward the start of their alignment areas.
end Aligns items toward the end of their alignment areas.
center Centers items within their alignment areas.
stretch Stretches eligible auto-sized items to fill their alignment areas along the relevant axis.
self-start Aligns each item toward its own start side, taking its writing mode into account.
self-end Aligns each item toward its own end side, taking its writing mode into account.
left Aligns items toward the physical left side where applicable.
right Aligns items toward the physical right side where applicable.
legacy Enables legacy alignment behavior with left, right, or center.
safe Modifies positional alignment to avoid certain overflow situations.
unsafe Allows the requested positional alignment even when overflow occurs.
initial Resets the property to normal.
inherit Uses the computed value from the parent element.
unset Resets the property to normal because it is not normally inherited.
revert Reverts the property according to cascade origin rules.
revert-layer Reverts the property according to cascade layer rules.

Property Characteristics

Characteristic Value
Initial value normal
Inherited No, except for the specified legacy behavior
Applies to All elements
Computed value As specified
Animation type Discrete
Percentages Not applicable
Primary alignment axis Inline axis
Common layout CSS Grid

The property establishes a default alignment for applicable child boxes. Individual items can override that alignment using justify-self.

How It Works

The justify-items property controls the inline-axis alignment of items within their own alignment areas, rather than distributing space between the items as a group.

Grid Container

.container {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  justify-items: center;
}

Each grid item is centered horizontally within its grid area in a typical horizontal writing mode.

Start Alignment

.container {
  display: grid;
  justify-items: start;
}

Each item aligns toward the inline-start edge of its grid area.

Stretch Alignment

.container {
  display: grid;
  justify-items: stretch;
}

Eligible auto-sized items expand along the inline axis to fill their available grid areas.

Important Consideration

Visible alignment changes depend on item sizing. If an item already fills its grid area, changing justify-items may not produce a noticeable difference.

normal Value

The normal value is the initial value. Its resulting alignment depends on the layout mode and the type of item.

Grid Default

.container {
  display: grid;
  justify-items: normal;
}

For most ordinary grid items, normal behaves like stretch.

Intrinsic Aspect Ratios

.container {
  display: grid;
  justify-items: normal;
}
.container img {
  max-width: 100%;
  height: auto;
}

Grid items with intrinsic sizes or aspect ratios, such as images, may use start alignment instead of stretching. This helps preserve their natural proportions.

Important Consideration

Do not assume that normal always stretches every grid item. Item sizing and intrinsic dimensions can affect the result.

start and end Values

The start and end values align items toward the logical start or end of their alignment areas.

Start Alignment

.container {
  display: grid;
  justify-items: start;
}

End Alignment

.container {
  display: grid;
  justify-items: end;
}

Fixed-Width Grid Items

.container {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  justify-items: end;
}
.container .item {
  width: 80px;
}

Each item is aligned toward the inline-end edge of its own grid area.

Important Consideration

Logical alignment adapts to writing modes and text direction. In a right-to-left horizontal layout, the inline-start edge is on the right.

center Value

The center value positions each item in the middle of its available alignment area along the inline axis.

Center Grid Items

.container {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  justify-items: center;
}

Center Cards Within Columns

.card-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  justify-items: center;
  gap: 20px;
}
.card-grid .card {
  width: 180px;
}

Center a Single Grid Item

.container {
  display: grid;
  justify-items: center;
}

The item is centered within its grid area, provided there is available space along the inline axis.

Important Consideration

justify-items: center does not center the entire grid track structure inside the container. Use justify-content when the tracks themselves need alignment.

stretch Value

The stretch value expands eligible auto-sized items to fill their available alignment areas along the inline axis.

Stretch Grid Items

.container {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  justify-items: stretch;
}

Items with Explicit Widths

.container {
  display: grid;
  justify-items: stretch;
}
.container .item {
  width: 100px;
}

An explicit width generally prevents the item from stretching to fill the grid area.

Items with Maximum Widths

.container {
  display: grid;
  justify-items: stretch;
}
.container .item {
  max-width: 250px;
}

The item can stretch within its available area while respecting its maximum width.

Important Consideration

Stretching affects the item's used size when its sizing properties allow it. It does not override explicit sizing constraints or minimum and maximum size limits.

self-start and self-end Values

The self-start and self-end values align each item according to its own writing mode and direction.

Self-Start Alignment

.container {
  display: grid;
  justify-items: self-start;
}

Self-End Alignment

.container {
  display: grid;
  justify-items: self-end;
}

Mixed Text Directions

.container {
  display: grid;
  justify-items: self-start;
}
.container .rtl-item {
  direction: rtl;
}

Items with different writing directions can align according to their individual start sides rather than the container's start side.

Important Consideration

Use start and end when alignment should follow the container. Use self-start and self-end when each item's own writing direction should determine alignment.

left and right Values

The left and right values provide physical alignment along the horizontal axis.

Left Alignment

.container {
  display: grid;
  justify-items: left;
}

Right Alignment

.container {
  display: grid;
  justify-items: right;
}

Physical Alignment vs. Logical Alignment

.logical {
  justify-items: start;
}
.physical {
  justify-items: left;
}

In a right-to-left horizontal layout, start follows the logical inline-start side, while left continues to refer to the physical left side.

Important Consideration

When the alignment axis is not parallel to the physical left-to-right axis, left and right behave like start. Logical values are generally more adaptable for multilingual layouts.

Legacy Alignment Values

The legacy keyword provides compatibility with older alignment behavior, particularly for certain traditional layout patterns.

Legacy Center Alignment

.container {
  justify-items: legacy center;
}

Legacy Left Alignment

.container {
  justify-items: legacy left;
}

Legacy Right Alignment

.container {
  justify-items: legacy right;
}

Inheritance Behavior

Unlike ordinary justify-items values, legacy alignment values have special inheritance behavior designed to preserve traditional alignment patterns.

Important Consideration

For modern Grid layouts, use start, end, center, or stretch unless legacy behavior is specifically required.

safe and unsafe Keywords

The safe and unsafe keywords modify positional alignment when items may overflow their alignment areas.

Safe Center Alignment

.container {
  display: grid;
  justify-items: safe center;
}

If centering would cause unsafe overflow, the alignment can fall back toward the start side.

Unsafe Center Alignment

.container {
  display: grid;
  justify-items: unsafe center;
}

This requests center alignment even if an oversized item extends beyond its alignment area.

Safe End Alignment

.container {
  display: grid;
  justify-items: safe end;
}

Important Consideration

Overflow alignment does not resize oversized items. It changes the alignment behavior when the requested position would create unsafe overflow.

justify-items in Grid

CSS Grid is the most common layout context for justify-items. The property sets the default inline-axis alignment for grid items within their grid areas.

Three-Column Grid

.container {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  justify-items: center;
  gap: 20px;
}

Start-Aligned Grid Items

.container {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  justify-items: start;
}

Stretch Grid Items

.container {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  justify-items: stretch;
}

Override One Grid Item

.container {
  display: grid;
  justify-items: center;
}
.container .featured {
  justify-self: end;
}

Most items are centered, while the featured item aligns toward the inline-end edge of its grid area.

Important Consideration

The property aligns grid items within their individual areas. It does not change the number of columns, the track sizes, or the placement of grid lines.

justify-items in Flexbox

The justify-items property does not affect item alignment in Flexbox. Flexbox uses other properties to control main-axis and cross-axis alignment.

Ineffective Flexbox Declaration

.container {
  display: flex;
  justify-items: center;
}

This declaration does not center flex items.

Main-Axis Alignment

.container {
  display: flex;
  justify-content: center;
}

Cross-Axis Alignment

.container {
  display: flex;
  align-items: center;
}

Center Along Both Axes

.container {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 250px;
}

Important Consideration

Use justify-content to distribute flex items along the main axis and align-items to align them along the cross axis. Do not use justify-items for flex item alignment.

Block Layout

The CSS Box Alignment specification also defines inline-axis alignment behavior for block layout. However, implementation support and the exact effects depend on the layout context.

Block Container Example

.container {
  justify-items: center;
}

In supporting block layout implementations, this can establish a default inline-axis alignment for applicable child boxes.

Reliable Grid Alternative

.container {
  display: grid;
  justify-items: center;
}

Using Grid provides well-established behavior for aligning items within their layout areas.

Important Consideration

Do not assume that justify-items behaves identically in block layout and Grid. Check browser support for the particular layout mode being used.

Writing Modes and Direction

The justify-items property operates along the inline axis. The physical direction of that axis depends on the writing mode and text direction.

Left-to-Right Layout

.container {
  display: grid;
  direction: ltr;
  justify-items: start;
}

In a horizontal writing mode, start alignment places items toward the left side of their grid areas.

Right-to-Left Layout

.container {
  display: grid;
  direction: rtl;
  justify-items: start;
}

In a horizontal writing mode, start alignment places items toward the right side.

Vertical Writing Mode

.container {
  display: grid;
  writing-mode: vertical-rl;
  justify-items: start;
}

The inline axis runs vertically in this writing mode, so inline-axis alignment is vertical rather than horizontal.

Writing Mode Comparison

Writing Mode Direction Inline-Start Side
horizontal-tb ltr Left
horizontal-tb rtl Right
vertical-rl ltr Top
vertical-rl rtl Bottom
vertical-lr ltr Top
vertical-lr rtl Bottom

Important Consideration

Use logical alignment values such as start and end when the layout should adapt naturally to different writing modes and text directions.

Item Sizing and Alignment

The visible effect of justify-items depends on the item's width, intrinsic dimensions, and available space within its alignment area.

Fixed-Width Items

.container {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  justify-items: center;
}
.container .item {
  width: 100px;
}

Each item can be centered because its width is smaller than the available grid area.

Auto-Sized Items

.container {
  display: grid;
  justify-items: stretch;
}
.container .item {
  width: auto;
}

Eligible items can stretch to occupy the available inline size.

Maximum Width

.container {
  display: grid;
  justify-items: center;
}
.container .item {
  width: 100%;
  max-width: 300px;
}

The item can use the available width up to its maximum, then remain centered when additional space is available.

Images

.container {
  display: grid;
  justify-items: center;
}
.container img {
  max-width: 100%;
  height: auto;
}

This is useful for centering images within grid areas while preserving their aspect ratios.

Important Consideration

Alignment does not replace sizing. Use width, maximum width, minimum width, and other sizing properties to control how much space an item occupies.

justify-items vs. justify-content

Both properties operate along the inline axis in Grid, but they align different parts of the layout.

Property Purpose
justify-items Sets the default alignment of items within their individual grid areas.
justify-content Aligns and distributes the grid tracks within the grid container.

Align Grid Items

.container {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  justify-items: center;
}

Align Grid Tracks

.container {
  display: grid;
  grid-template-columns: repeat(3, 100px);
  justify-content: center;
}

Combine Both

.container {
  display: grid;
  grid-template-columns: repeat(3, 120px);
  justify-content: center;
  justify-items: center;
}

The grid tracks are centered within the container, and each item is centered within its own grid area.

justify-items vs. justify-self

The justify-items property establishes a default alignment for applicable child items, while justify-self controls the alignment of an individual item.

Container Alignment

.container {
  display: grid;
  justify-items: center;
}

Individual Override

.container {
  display: grid;
  justify-items: center;
}
.container .special {
  justify-self: end;
}

All items are centered except the special item, which aligns toward the inline-end edge of its grid area.

Important Consideration

Use justify-items for consistent default alignment across a container and justify-self for exceptions.

justify-items and align-items

In Grid, justify-items and align-items work together to control alignment along the inline and block axes.

Property Grid Alignment Axis
justify-items Inline axis
align-items Block axis

Center Items Along Both Axes

.container {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-auto-rows: 150px;
  justify-items: center;
  align-items: center;
}

Different Alignment Values

.container {
  display: grid;
  justify-items: end;
  align-items: start;
}

In a typical left-to-right horizontal writing mode, items align toward the right and top edges of their grid areas.

Important Consideration

The inline and block axes depend on the writing mode. They should not always be treated as horizontal and vertical.

place-items Shorthand

The place-items shorthand sets both align-items and justify-items in a single declaration.

Two Values

.container {
  place-items: start center;
}

This is equivalent to:

.container {
  align-items: start;
  justify-items: center;
}

One Value

.container {
  place-items: center;
}

This is equivalent to:

.container {
  align-items: center;
  justify-items: center;
}

Override the Inline-Axis Alignment

.container {
  place-items: center;
  justify-items: end;
}

The later justify-items declaration changes the inline-axis alignment while leaving align-items: center unchanged.

Important Consideration

The first place-items value controls align-items, and the second controls justify-items. When the second value is omitted, it generally uses the first value, subject to shorthand grammar rules.

Inheritance

The justify-items property is not normally inherited. Its initial value is normal, although legacy alignment values have special inheritance behavior.

Parent Alignment

.parent {
  display: grid;
  justify-items: center;
}

A nested grid container does not automatically receive justify-items: center as its own computed value.

Explicit Inheritance

.child {
  display: grid;
  justify-items: inherit;
}

Reset to Initial Value

.child {
  justify-items: initial;
}

This resets the property to normal.

Using unset

.child {
  justify-items: unset;
}

For ordinary alignment values, unset resets the property to its initial value.

Important Consideration

Legacy alignment values are an exception to the normal inheritance behavior. Use explicit declarations for predictable alignment in modern layouts.

justify-items Example

This example compares four common justify-items values. Each grid contains three columns, and the items demonstrate how alignment changes within their individual grid areas.

HTML Example

<div class="justify-items-demo">
  <div class="demo-row">
    <h3>start</h3>
    <div class="demo-grid start">
      <div class="demo-item">1</div>
      <div class="demo-item">2</div>
      <div class="demo-item">3</div>
    </div>
  </div>
  <div class="demo-row">
    <h3>center</h3>
    <div class="demo-grid center">
      <div class="demo-item">1</div>
      <div class="demo-item">2</div>
      <div class="demo-item">3</div>
    </div>
  </div>
  <div class="demo-row">
    <h3>end</h3>
    <div class="demo-grid end">
      <div class="demo-item">1</div>
      <div class="demo-item">2</div>
      <div class="demo-item">3</div>
    </div>
  </div>
  <div class="demo-row">
    <h3>stretch</h3>
    <div class="demo-grid stretch">
      <div class="demo-item">1</div>
      <div class="demo-item">2</div>
      <div class="demo-item">3</div>
    </div>
  </div>
</div>

CSS Example

.justify-items-demo .demo-row {
  margin-bottom: 20px;
}
.justify-items-demo h3 {
  margin: 0 0 8px;
  font-size: 1rem;
}
.justify-items-demo .demo-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  padding: 10px;
  border: 2px solid #2563eb;
  background-color: #eff6ff;
}
.justify-items-demo .demo-item {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 45px;
  height: 45px;
  background-color: #2563eb;
  color: #fff;
  font-weight: bold;
}
.justify-items-demo .start {
  justify-items: start;
}
.justify-items-demo .center {
  justify-items: center;
}
.justify-items-demo .end {
  justify-items: end;
}
.justify-items-demo .stretch {
  justify-items: stretch;
}
.justify-items-demo .stretch .demo-item {
  width: auto;
}
Browser Result

start

1
2
3

center

1
2
3

end

1
2
3

stretch

1
2
3

The first three grids show items aligned toward the start, center, or end of each grid area. The final grid demonstrates how eligible auto-width items stretch to fill the available inline space.

Try Right-to-Left Direction

.justify-items-demo .demo-grid {
  direction: rtl;
}

The logical start and end positions reverse in a horizontal writing mode.

Try a Maximum Width

.justify-items-demo .stretch .demo-item {
  width: auto;
  max-width: 80px;
}

The stretch-aligned items respect the maximum width instead of expanding across their entire grid areas.

Common Mistakes

Using justify-items to Align Flex Items

.container {
  display: flex;
  justify-items: center;
}

This does not center flex items. Use justify-content for main-axis alignment and align-items for cross-axis alignment.

Confusing Item Alignment with Track Alignment

justify-items aligns items inside their grid areas. It does not center the grid tracks as a group.

Expecting Stretch to Override Fixed Widths

.container {
  display: grid;
  justify-items: stretch;
}
.container .item {
  width: 100px;
}

The explicit width generally prevents the item from stretching across the available inline space.

Using an Invalid Value

.container {
  justify-items: space-between;
}

This is invalid. Distributed alignment values such as space-between belong to justify-content, not justify-items.

Assuming start Always Means Left

Logical alignment follows writing mode and direction. The start side can be right, top, or bottom depending on the layout.

Ignoring justify-self Overrides

An individual grid item can override the container's justify-items value with justify-self.

Expecting Item Alignment to Change Grid Track Sizes

The property does not directly change grid-template columns or rows. It aligns items within the areas produced by the grid layout.

Important Considerations

Keep the following points in mind when using justify-items:

  • The property sets the default inline-axis alignment of applicable child items.
  • It is most commonly used in CSS Grid.
  • The initial value is normal.
  • The property is not normally inherited.
  • Legacy alignment values have special inheritance behavior.
  • start and end follow the container's logical alignment axis.
  • self-start and self-end account for each item's own writing direction.
  • center centers items within their alignment areas.
  • stretch expands eligible auto-sized items.
  • Explicit widths and sizing constraints can prevent stretching.
  • Intrinsic aspect ratios can affect the behavior of normal.
  • left and right provide physical alignment where applicable.
  • safe and unsafe modify overflow alignment behavior.
  • justify-items does not control flex item alignment.
  • justify-content aligns grid tracks as a group.
  • justify-self overrides the default alignment for an individual item.
  • align-items controls block-axis alignment in Grid.
  • place-items combines align-items and justify-items.
  • Writing mode and direction affect the physical orientation of the inline axis.
  • Block layout support and behavior can differ from Grid.
  • The property animates discretely rather than interpolating between alignment values.

Browser Support

The CSS justify-items property is widely supported in modern browsers, including Chrome, Edge, Firefox, Safari, and Opera, particularly for CSS Grid layouts.

Support for some alignment values and for application outside Grid, including block layout, may vary. Test these cases when consistent behavior across browsers is required.

For current compatibility information, visit Can I Use? and search for justify-items.

Specifications

The justify-items property is defined in the CSS Box Alignment Module Level 3 specification.

CSS Box Alignment Module Level 3: justify-items

The specification defines default self-alignment, logical alignment values, overflow alignment, and legacy alignment behavior.

For additional documentation and examples, consult MDN Web Docs.

MDN Web Docs: justify-items