CSS place-items Property
The CSS place-items property is a shorthand for align-items and justify-items, controlling how items are aligned along two axes within their layout areas.
It is particularly useful in CSS Grid, where it can center items, align them toward the edges of their grid areas, or stretch them to fill available space. In Flexbox, the align-items component works, but justify-items does not affect flex items.
place-items Syntax
The place-items property accepts one or two alignment values. The first sets align-items, and the second sets justify-items.
Basic Syntax
selector {
place-items: center;
}
This is equivalent to setting both align-items and justify-items to center.
Two-Value Syntax
selector {
place-items: start end;
}
The first value controls alignment along the block axis in Grid. The second controls alignment along the inline axis.
Common Values
.container {
place-items: normal;
}
.container {
place-items: center;
}
.container {
place-items: start;
}
.container {
place-items: end center;
}
.container {
place-items: stretch;
}
.container {
place-items: center start;
}
Safe Alignment
.container {
place-items: safe center;
}
.container {
place-items: safe center safe end;
}
The safe keyword modifies positional alignment to help avoid overflow-related data loss where applicable.
CSS-Wide Keywords
.container {
place-items: initial;
}
.container {
place-items: inherit;
}
.container {
place-items: unset;
}
.container {
place-items: revert;
}
.container {
place-items: revert-layer;
}
CSS-wide keywords must be used individually and cannot be combined with other alignment values.
Property Values
The shorthand accepts alignment values supported by its two longhand properties. The exact behavior depends on the layout method and the available alignment space.
| Value | Description |
|---|---|
normal |
Uses the normal item-alignment behavior for the layout context. |
start |
Aligns items toward the start of the relevant alignment axis. |
end |
Aligns items toward the end of the relevant alignment axis. |
center |
Centers items within their available alignment space. |
stretch |
Stretches eligible items to fill their alignment areas, subject to sizing constraints. |
self-start |
Aligns items toward the start side determined by each item's own writing mode. |
self-end |
Aligns items toward the end side determined by each item's own writing mode. |
flex-start |
Aligns items toward the flex-start side in applicable flex layouts. |
flex-end |
Aligns items toward the flex-end side in applicable flex layouts. |
baseline |
Aligns items using their first baseline where baseline alignment is supported. |
first baseline |
Requests first-baseline alignment. |
last baseline |
Requests last-baseline alignment. |
safe |
Modifies supported positional alignment to avoid certain overflow situations. |
unsafe |
Requests the specified positional alignment even if overflow may occur. |
legacy |
Can be used with supported justify-items values such as legacy center in the second component. |
initial |
Resets both longhand properties to normal. |
inherit |
Inherits both longhand values from the parent element. |
unset |
Resets both longhand properties to their initial values because they are not inherited. |
revert |
Reverts the shorthand according to CSS cascade origin rules. |
revert-layer |
Reverts the shorthand according to CSS cascade layer rules. |
Property Characteristics
| Characteristic | Value |
|---|---|
| Initial value | normal normal |
| Inherited | No, for both longhand properties |
| Applies to | Containers that support the underlying item-alignment properties |
| Computed value | See align-items and justify-items |
| Animation type | Discrete for the underlying alignment properties |
| Percentages | Not applicable to alignment values |
| Longhand properties | align-items and justify-items |
Valid Values
.container {
place-items: center;
}
.container {
place-items: start end;
}
.container {
place-items: stretch;
}
.container {
place-items: center start;
}
.container {
place-items: first baseline center;
}
.container {
place-items: safe center;
}
.container {
place-items: center legacy center;
}
Invalid Values
.container {
place-items: middle;
}
.container {
place-items: space-between;
}
.container {
place-items: 50%;
}
.container {
place-items: center, start;
}
.container {
place-items: center start end;
}
The property does not accept arbitrary alignment keywords, content-distribution values such as space-between, percentages, comma-separated values, or three independent alignment components.
How It Works
The place-items property combines two item-alignment declarations into one shorthand.
The Two Longhand Properties
.container {
align-items: center;
justify-items: end;
}
The equivalent shorthand is:
.container {
place-items: center end;
}
Alignment Within Grid Areas
In Grid, each item occupies a grid area. The align-items component controls its block-axis alignment, and justify-items controls its inline-axis alignment.
Available Alignment Space
Alignment differences are most visible when an item is smaller than its assigned grid area. If an item fills the entire area, centering or edge alignment may produce little or no visible change.
Default Stretching
Grid items with automatic sizing often stretch to fill their grid areas. Setting place-items: center can prevent that stretching and allow items to use their intrinsic or specified dimensions.
Container-Level Declaration
Apply place-items to the grid container to establish the default alignment for its items.
Individual Overrides
Use place-self, align-self, or justify-self on an individual item when it needs different alignment.
One Value vs. Two Values
The shorthand supports a single value for matching alignment or two values for different alignment along each axis.
One Value
.container {
place-items: center;
}
This expands to:
.container {
align-items: center;
justify-items: center;
}
Two Values
.container {
place-items: start end;
}
This expands to:
.container {
align-items: start;
justify-items: end;
}
Different Alignment for Each Axis
.container {
place-items: end center;
}
This aligns items toward the block-end side of their grid areas and centers them along the inline axis.
Stretching on One Axis
.container {
place-items: stretch center;
}
Eligible items stretch along the block axis while remaining centered along the inline axis.
Choosing a Form
Use one value for the same alignment on both axes. Use two values when items need different alignment behavior along the block and inline axes.
Using place-items With CSS Grid
CSS Grid provides a straightforward use for place-items because items can be aligned independently within their assigned grid areas.
Centering Grid Items
.grid-container {
display: grid;
grid-template-columns: repeat(2, 150px);
grid-auto-rows: 120px;
place-items: center;
}
Each grid item is centered horizontally and vertically within its grid area.
Aligning Items to the Start
.grid-container {
display: grid;
grid-template-columns: repeat(2, 150px);
grid-auto-rows: 120px;
place-items: start;
}
Items are aligned toward the start of both axes within their grid areas.
Aligning Items to the End
.grid-container {
display: grid;
grid-template-columns: repeat(2, 150px);
grid-auto-rows: 120px;
place-items: end;
}
Items are aligned toward the end of both axes.
Different Alignment on Each Axis
.grid-container {
display: grid;
grid-template-columns: repeat(2, 150px);
grid-auto-rows: 120px;
place-items: start center;
}
Items align toward the block-start side and remain centered along the inline axis.
Stretching Grid Items
.grid-container {
display: grid;
grid-template-columns: repeat(2, 150px);
grid-auto-rows: 120px;
place-items: stretch;
}
Eligible items stretch to fill their grid areas. Explicit sizing, intrinsic aspect ratios, and other sizing constraints can limit the effect.
Centering a Single Grid Item
.grid-container {
display: grid;
width: 300px;
height: 200px;
place-items: center;
}
This is a convenient way to center a single item within a grid container.
Important Consideration
place-items aligns items within grid areas. It does not distribute the grid tracks themselves within the container.
Using place-items With Flexbox
The place-items shorthand can be declared on a flex container, but only its align-items component affects flex item alignment.
Cross-Axis Alignment
.flex-container {
display: flex;
height: 200px;
place-items: center;
}
In a typical row flex container, the items are centered vertically because align-items is set to center.
Why justify-items Has No Effect
Flexbox uses justify-content to distribute items along the main axis. The justify-items property does not affect flex items.
Centering Flex Items on Both Axes
.flex-container {
display: flex;
align-items: center;
justify-content: center;
min-height: 200px;
}
Use align-items and justify-content to center flex items along both axes.
Column Flex Direction
.flex-container {
display: flex;
flex-direction: column;
place-items: center;
}
With a column flex direction in a typical horizontal writing mode, align-items: center centers items horizontally along the cross axis.
Using Two Values
.flex-container {
display: flex;
place-items: start end;
}
The first value sets align-items: start. The second sets justify-items: end, which has no effect on flex items.
Important Consideration
For Flexbox, using align-items directly is often clearer than using place-items, especially when teaching the difference between main-axis and cross-axis alignment.
Understanding Alignment Values
Alignment values determine where items sit within their available alignment areas.
start
.container {
place-items: start;
}
Aligns items toward the start of both alignment axes.
end
.container {
place-items: end;
}
Aligns items toward the end of both alignment axes.
center
.container {
place-items: center;
}
Centers items within their alignment areas.
stretch
.container {
place-items: stretch;
}
Stretches eligible items along both axes, subject to sizing constraints.
self-start and self-end
.container {
place-items: self-start;
}
.container {
place-items: self-end;
}
These values use the individual item's writing mode to determine its start and end sides.
Baseline Alignment
.container {
place-items: first baseline;
}
.container {
place-items: last baseline;
}
Baseline alignment positions eligible items according to their text or content baselines, rather than simply centering their boxes.
Safe Alignment
.container {
place-items: safe center;
}
Safe alignment can help prevent content from being positioned where it becomes inaccessible due to overflow.
Unsafe Alignment
.container {
place-items: unsafe center;
}
Unsafe alignment requests the specified position even if it results in overflow.
Important Consideration
Values such as space-between, space-around, and space-evenly are content-distribution values, not valid values for place-items.
place-items vs. place-content
Although their names are similar, place-items and place-content control different levels of alignment.
place-items
.grid-container {
display: grid;
place-items: center;
}
Centers individual items within their grid areas.
place-content
.grid-container {
display: grid;
place-content: center;
}
Centers the grid tracks as a group within the container when extra space is available.
Using Both Properties
.grid-container {
display: grid;
grid-template-columns: repeat(2, 120px);
grid-auto-rows: 100px;
width: 400px;
height: 300px;
place-content: center;
place-items: center;
}
The grid tracks are centered within the container, and the individual items are centered within their grid areas.
Property Comparison
| Property | Longhand Properties | Purpose |
|---|---|---|
place-content |
align-content, justify-content |
Aligns and distributes content groups within a container. |
place-items |
align-items, justify-items |
Controls the default alignment of individual items. |
place-self |
align-self, justify-self |
Controls alignment of an individual item. |
Important Consideration
Use place-content when the overall grid structure needs alignment. Use place-items when the items inside the grid areas need alignment.
Overriding Alignment With place-self
The place-self property allows an individual item to override the default alignment established by its container.
Container Alignment
.grid-container {
display: grid;
place-items: center;
}
All grid items are centered by default.
Individual Item Override
.special-item {
place-self: end start;
}
The selected item aligns toward the block-end and inline-start sides of its grid area.
Complete Example
<div class="grid-container">
<div class="grid-item">One</div>
<div class="grid-item special-item">Two</div>
<div class="grid-item">Three</div>
</div>
.grid-container {
display: grid;
grid-template-columns: repeat(3, 120px);
grid-auto-rows: 100px;
place-items: center;
}
.special-item {
place-self: end start;
}
The first and third items remain centered, while the second item uses its own alignment.
Longhand Alternatives
.special-item {
align-self: end;
justify-self: start;
}
These declarations are equivalent to place-self: end start.
Important Consideration
Use container-level alignment for consistent defaults and item-level alignment only where exceptions are needed.
Writing Modes and Alignment Axes
CSS item alignment uses logical axes that can change according to writing mode and text direction.
Horizontal Writing Mode
.grid-container {
writing-mode: horizontal-tb;
place-items: start end;
}
In a typical left-to-right horizontal writing mode, the block axis runs vertically and the inline axis runs horizontally.
Vertical Writing Mode
.grid-container {
writing-mode: vertical-rl;
place-items: start end;
}
In vertical writing mode, the block axis runs horizontally and the inline axis runs vertically.
Text Direction
.grid-container {
direction: rtl;
place-items: start;
}
Right-to-left text direction changes which physical side corresponds to inline-start and inline-end.
self-start vs. start
The start value follows the alignment container's relevant axis, while self-start uses the item's own writing mode to determine the appropriate start side.
Important Consideration
Logical alignment values help layouts adapt to different writing modes without requiring separate left, right, top, or bottom positioning rules.
place-items Example
The following example compares three item-alignment settings. Each grid contains four smaller items, making their positions within the grid areas easy to see.
HTML Example
<div class="place-items-demo">
<div class="demo-item">
<h3>Start</h3>
<div class="demo-grid items-start">
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
</div>
</div>
<div class="demo-item">
<h3>Center</h3>
<div class="demo-grid items-center">
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
</div>
</div>
<div class="demo-item">
<h3>End</h3>
<div class="demo-grid items-end">
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
</div>
</div>
</div>
CSS Example
.place-items-demo {
display: flex;
flex-wrap: wrap;
gap: 20px;
}
.demo-item {
flex: 1 1 180px;
}
.demo-item h3 {
text-align: center;
}
.demo-grid {
display: grid;
grid-template-columns: repeat(2, 1fr);
grid-template-rows: repeat(2, 90px);
gap: 8px;
padding: 10px;
border: 2px solid #94a3b8;
background-color: #f1f5f9;
}
.demo-grid > div {
display: grid;
place-items: center;
width: 40px;
height: 40px;
background-color: #2563eb;
color: #ffffff;
font-weight: 700;
}
.items-start {
place-items: start;
}
.items-center {
place-items: center;
}
.items-end {
place-items: end;
}
Start
Center
End
Each grid uses the same track sizes and item dimensions. The difference is where the items appear inside their individual grid areas.
Expected Behavior
| Value | Result |
|---|---|
start |
Items align toward the start of both axes within their grid areas. |
center |
Items are centered within their grid areas. |
end |
Items align toward the end of both axes within their grid areas. |
Practical Centering Example
.icon-container {
display: grid;
place-items: center;
width: 80px;
height: 80px;
border: 1px solid #94a3b8;
}
.icon-container svg {
width: 32px;
height: 32px;
}
This centers an SVG icon within a fixed-size container without requiring margins or absolute positioning.
Accessibility Considerations
The place-items property changes visual alignment without changing the semantic structure or source order of HTML elements.
Maintain Logical Source Order
Keep elements in a meaningful HTML order so keyboard and screen reader navigation remain predictable.
Avoid Clipping Content
Alignment values can position items where they overflow their grid areas. Ensure important text and controls remain visible.
Use Safe Alignment When Appropriate
.grid-container {
place-items: safe center;
}
Safe alignment can help avoid certain overflow situations that would otherwise make content difficult to access.
Support Responsive Layouts
Test item alignment at different viewport sizes. Fixed-size items may not fit inside narrow grid tracks.
Preserve Interactive Target Sizes
When aligning buttons, links, or other interactive elements, maintain adequate clickable and touch-friendly target sizes.
Important Consideration
Visual alignment should improve layout without making content harder to read, navigate, or interact with.
Common Mistakes
Confusing place-items With place-content
place-items aligns individual items, while place-content aligns the overall content structure.
Expecting Both Axes to Work in Flexbox
.flex-container {
display: flex;
place-items: center;
}
Only the align-items component affects flex items. Use justify-content for main-axis alignment.
Using space-between
.container {
place-items: space-between;
}
The space-between value belongs to content distribution and is not valid for place-items.
Using Percentages
.container {
place-items: 50%;
}
Percentages are not valid item-alignment values.
Using Commas
.container {
place-items: center, start;
}
Separate the two alignment components with spaces, not commas.
Applying the Property to a Grid Item
.grid-item {
place-items: center;
}
This does not control the item's own alignment within its parent grid area. Use place-self on the item instead. The declaration could still affect the item's children if it establishes a suitable alignment container.
Forgetting Item Sizing
Explicit widths, heights, minimum sizes, and aspect ratios can limit stretching or make alignment changes less noticeable.
Assuming start Always Means Left
The physical direction of start depends on the relevant alignment axis, writing mode, and text direction.
Overwriting Longhand Values
.container {
justify-items: end;
place-items: center;
}
The later shorthand resets both align-items and justify-items to center.
Ignoring Individual Overrides
An item with its own align-self, justify-self, or place-self declaration may not follow the container's default alignment.
Important Considerations
Keep the following points in mind when using place-items:
- It is a shorthand for
align-itemsandjustify-items. - Its initial longhand values are both
normal. - The underlying properties are not inherited.
- It accepts one or two alignment components.
- The first component sets
align-items. - The second component sets
justify-items. - When one value is supplied, it applies to both longhand properties.
- It is especially useful for CSS Grid layouts.
- In Grid, it controls item alignment within individual grid areas.
- It does not distribute grid tracks within the container.
- Use
place-contentto align the overall grid structure. - Use
place-selfto override alignment for an individual item. - In Flexbox, the
align-itemscomponent controls cross-axis item alignment. - The
justify-itemscomponent has no effect on flex items. - Use
justify-contentfor main-axis distribution in Flexbox. centercenters eligible items within their alignment areas.startandendalign items toward the corresponding logical sides.stretchcan expand eligible items to fill available space.- Explicit sizing and intrinsic aspect ratios can limit stretching.
- Baseline alignment can align items according to their content baselines.
safeandunsafemodify supported positional alignment values.- Content-distribution values such as
space-betweenare not valid. - Percentages are not accepted as alignment values.
- Alignment components are separated by spaces, not commas.
- Logical alignment directions depend on writing mode and text direction.
- The shorthand resets both underlying longhand properties.
- Individual self-alignment properties can override the container defaults.
- Item alignment does not change HTML source order.
- Test item sizing and alignment at different viewport widths.
- Ensure interactive items remain visible and accessible.
Browser Support
The CSS place-items property is Widely available in modern browsers, including Chrome, Edge, Firefox, and Safari.
The shorthand is well supported, but the behavior of its underlying alignment properties depends on the layout method. In particular, justify-items does not affect flex items.
For current compatibility information, visit Can I Use? and search for place-items.
Specifications
The place-items property is defined in CSS Box Alignment Module Level 3.
CSS Box Alignment Module Level 3
The specification defines the shorthand syntax and its relationship to align-items and justify-items.
For additional documentation and examples, consult MDN Web Docs.
