CSS place-content Property
The CSS place-content property is a shorthand for align-content and justify-content, controlling how content is distributed along the block and inline axes.
It is useful in CSS Grid, Flexbox, and other supported alignment layouts. With one declaration, you can center content, distribute extra space, or position groups of tracks or flex lines within a container. Its visible effect depends on the layout method and available space.
place-content Syntax
The place-content property accepts one or two alignment values. The first controls align-content, while the second controls justify-content.
Basic Syntax
selector {
place-content: center;
}
This is equivalent to setting both align-content and justify-content to center.
Two-Value Syntax
selector {
place-content: center space-between;
}
The first value controls alignment along the block axis. The second controls alignment along the inline axis.
Common Values
.container {
place-content: normal;
}
.container {
place-content: center;
}
.container {
place-content: start end;
}
.container {
place-content: space-between;
}
.container {
place-content: space-around space-evenly;
}
.container {
place-content: stretch;
}
Safe Alignment
.container {
place-content: safe center;
}
.container {
place-content: safe center safe end;
}
The safe keyword requests alignment that avoids the data loss associated with certain overflow situations. Its effect depends on the alignment context.
CSS-Wide Keywords
.container {
place-content: initial;
}
.container {
place-content: inherit;
}
.container {
place-content: unset;
}
.container {
place-content: revert;
}
.container {
place-content: revert-layer;
}
CSS-wide keywords must be used individually and cannot be combined with alignment values.
Property Values
The shorthand accepts values supported by its two longhand properties. Some values apply only in particular layout contexts.
| Value | Description |
|---|---|
normal |
Uses the normal content-alignment behavior for the layout method. |
start |
Aligns content toward the start of the relevant alignment axis. |
end |
Aligns content toward the end of the relevant alignment axis. |
center |
Centers the content within the available alignment space. |
flex-start |
Aligns content toward the flex-start side in flex layouts, with context-dependent behavior elsewhere. |
flex-end |
Aligns content toward the flex-end side in flex layouts, with context-dependent behavior elsewhere. |
space-between |
Distributes extra space between content groups without adding space at the outer edges. |
space-around |
Distributes extra space around content groups, with half-sized spaces at the outer edges. |
space-evenly |
Distributes equal space between content groups and at the outer edges. |
stretch |
Stretches eligible content tracks or lines to use available space, depending on the layout context. |
baseline |
Requests baseline alignment where supported by the applicable longhand and layout context. |
first baseline |
Requests alignment using the first baseline of the relevant content. |
last baseline |
Requests alignment using the last baseline of the relevant content. |
safe |
Modifies positional alignment to avoid unsafe overflow where applicable. |
unsafe |
Requests the specified positional alignment even when overflow may occur. |
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 |
| Applies to | Block containers, flex containers, and grid containers, according to the longhand properties |
| Computed value | See align-content and justify-content |
| Animation type | See individual longhand properties |
| Percentages | Not applicable to the shorthand's alignment values |
| Longhand properties | align-content and justify-content |
Valid Values
.container {
place-content: center;
}
.container {
place-content: start end;
}
.container {
place-content: space-between center;
}
.container {
place-content: space-around space-evenly;
}
.container {
place-content: stretch;
}
.container {
place-content: safe center;
}
.container {
place-content: first baseline center;
}
Invalid Values
.container {
place-content: middle;
}
.container {
place-content: left right;
}
.container {
place-content: center center center;
}
.container {
place-content: 50%;
}
.container {
place-content: space-between, center;
}
The shorthand does not accept arbitrary keywords, percentages, comma-separated alignment values, or more than two alignment components. The physical left and right keywords belong to justify-content and cannot be used as the first component of place-content.
How It Works
The place-content shorthand sets two independent alignment properties in a single declaration.
The Two Longhand Properties
.container {
align-content: center;
justify-content: space-between;
}
The equivalent shorthand is:
.container {
place-content: center space-between;
}
Block and Inline Axes
The align-content component controls alignment along the block axis, while justify-content controls alignment along the inline axis.
In a typical horizontal, left-to-right writing mode, the block axis runs vertically and the inline axis runs horizontally.
Available Space
Content alignment is most noticeable when the container has extra space along the relevant axis. If the content already occupies the available space, several alignment values may produce the same appearance.
Grid Alignment
In Grid layouts, the property can position and distribute the grid tracks as a group within the container.
Flexbox Alignment
In Flexbox, justify-content distributes flex items along the main axis, while align-content distributes flex lines along the cross axis when multiple lines exist.
Important Distinction
The shorthand does not align each individual grid item within its own grid area. That behavior is controlled by place-items or the individual item-alignment properties.
One Value vs. Two Values
One-value and two-value declarations provide different levels of control over content alignment.
One Value
.container {
place-content: center;
}
This expands to:
.container {
align-content: center;
justify-content: center;
}
Two Values
.container {
place-content: start space-between;
}
This expands to:
.container {
align-content: start;
justify-content: space-between;
}
Another Two-Value Example
.container {
place-content: space-around center;
}
This expands to:
.container {
align-content: space-around;
justify-content: center;
}
Special Case for One Value
When the single value is not valid for justify-content, the second component defaults to start. This is relevant to baseline alignment.
.container {
place-content: first baseline;
}
This sets align-content to first baseline and justify-content to start.
Choosing a Form
Use one value when the same alignment behavior is appropriate for both components. Use two values when the axes need different alignment settings.
Using place-content With CSS Grid
CSS Grid is one of the most useful environments for place-content because grid tracks can be aligned together within a larger container.
Centering Grid Tracks
.grid-container {
display: grid;
grid-template-columns: repeat(2, 100px);
grid-auto-rows: 80px;
width: 400px;
height: 300px;
place-content: center;
}
The grid tracks are centered horizontally and vertically within the container.
Aligning Tracks to the Start
.grid-container {
display: grid;
grid-template-columns: repeat(2, 100px);
grid-auto-rows: 80px;
width: 400px;
height: 300px;
place-content: start;
}
The grid tracks are positioned toward the start of both alignment axes.
Distributing Space Between Tracks
.grid-container {
display: grid;
grid-template-columns: repeat(3, 80px);
grid-auto-rows: 60px;
width: 400px;
height: 300px;
place-content: space-between;
}
Available space is distributed between grid tracks along both axes when there are enough tracks to distribute it.
Different Alignment on Each Axis
.grid-container {
display: grid;
grid-template-columns: repeat(2, 100px);
grid-auto-rows: 80px;
width: 400px;
height: 300px;
place-content: end center;
}
The grid tracks are aligned toward the block-end side and centered along the inline axis.
Stretching Auto-Sized Tracks
.grid-container {
display: grid;
grid-template-columns: repeat(2, auto);
grid-auto-rows: auto;
width: 400px;
height: 300px;
place-content: stretch;
}
Eligible auto-sized tracks can expand to occupy extra space. Fixed-size tracks do not stretch merely because place-content: stretch is specified.
Important Consideration
Grid content alignment positions the track structure within the container. To align individual items inside their grid areas, use place-items or place-self.
Using place-content With Flexbox
In Flexbox, the two components of place-content operate according to the flex layout's main and cross axes.
Single-Line Flex Container
.flex-container {
display: flex;
justify-content: center;
align-content: center;
}
In a single-line flex container, align-content has no effect. The justify-content component still controls main-axis distribution.
Using the Shorthand
.flex-container {
display: flex;
place-content: center;
}
In a typical single-line row flex container, the items are centered horizontally through justify-content. Vertical alignment of individual items is controlled by align-items.
Multiple Flex Lines
.flex-container {
display: flex;
flex-wrap: wrap;
width: 320px;
height: 300px;
gap: 10px;
place-content: space-between center;
}
When the flex items wrap into multiple lines, the first component distributes the lines along the cross axis, while the second centers items along the main axis.
Column Flex Direction
.flex-container {
display: flex;
flex-direction: column;
height: 300px;
place-content: center;
}
For a column flex container, justify-content controls vertical distribution in a typical horizontal writing mode. The align-content component affects cross-axis line distribution only when applicable.
Why the Axes Can Be Confusing
In Grid, the shorthand's components correspond to block-axis and inline-axis content alignment. In Flexbox, the underlying longhand properties follow the flex cross and main axes.
Important Consideration
Do not assume place-content: center centers individual flex items on both axes. Use align-items: center when cross-axis item alignment is needed.
Understanding Alignment Values
Different alignment values control how available space is distributed around or between content groups.
start and end
.container {
place-content: start;
}
.container {
place-content: end;
}
These values align content toward the start or end of the relevant alignment axes.
center
.container {
place-content: center;
}
Centers content within the available alignment space.
space-between
.container {
place-content: space-between;
}
Distributes extra space between content groups. The first and last groups are positioned at the corresponding edges when there is positive free space.
space-around
.container {
place-content: space-around;
}
Distributes space around each group. Outer edge spaces are half the size of the spaces between adjacent groups.
space-evenly
.container {
place-content: space-evenly;
}
Distributes equal space between groups and at the outer edges.
stretch
.container {
place-content: stretch;
}
Allows eligible content tracks or lines to stretch into available space, depending on the layout method.
Safe and Unsafe Alignment
.container {
place-content: safe center;
}
.container {
place-content: unsafe end;
}
The safe and unsafe modifiers affect how positional alignment behaves when content may overflow.
Baseline Alignment
.container {
place-content: first baseline center;
}
Baseline alignment can be used where the applicable layout and alignment context support it. Its result depends on the baselines available from the content.
place-content vs. place-items
The place-content and place-items properties both combine two alignment properties, but they control different aspects of layout.
place-content
.grid-container {
display: grid;
place-content: center;
}
Controls the alignment of the grid tracks as a group within the container.
place-items
.grid-container {
display: grid;
place-items: center;
}
Controls how individual grid items align within their grid areas.
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 default alignment of individual items. |
place-self |
align-self, justify-self |
Controls alignment of an individual item. |
Important Consideration
Use place-content to position or distribute the content structure. Use place-items to control how individual items sit within their assigned areas.
Writing Modes and Alignment Axes
CSS alignment uses logical axes rather than always referring to the physical horizontal and vertical directions.
Horizontal Writing Mode
.container {
writing-mode: horizontal-tb;
place-content: start end;
}
In this writing mode, the block axis runs vertically and the inline axis runs horizontally.
Vertical Writing Mode
.container {
writing-mode: vertical-rl;
place-content: start end;
}
In this writing mode, the block axis runs horizontally and the inline axis runs vertically. The physical directions associated with logical alignment values change accordingly.
Text Direction
.container {
direction: rtl;
place-content: start;
}
Text direction can influence the physical side corresponding to inline-start and inline-end.
Flexbox Axis Behavior
Flexbox adds another consideration because its main and cross axes depend on flex-direction and the writing mode.
Important Consideration
Use logical alignment values such as start and end when layouts should adapt to different writing directions.
place-content Example
The following example compares three alignment settings in CSS Grid containers. Each container has the same dimensions and grid tracks, but the content is positioned differently.
HTML Example
<div class="place-content-demo">
<div class="demo-item">
<h3>Start</h3>
<div class="demo-grid grid-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 grid-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 grid-end">
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
</div>
</div>
</div>
CSS Example
.place-content-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, 50px);
grid-template-rows: repeat(2, 50px);
width: 100%;
height: 200px;
gap: 8px;
padding: 10px;
border: 2px solid #94a3b8;
background-color: #f1f5f9;
}
.demo-grid > div {
display: grid;
place-items: center;
background-color: #2563eb;
color: #ffffff;
font-weight: 700;
}
.grid-start {
place-content: start;
}
.grid-center {
place-content: center;
}
.grid-end {
place-content: end;
}
Start
Center
End
The first grid positions its tracks at the start of both axes. The second centers the tracks, and the third positions them at the end. The grid item sizes remain unchanged.
Using Different Values for Each Axis
.grid-container {
display: grid;
grid-template-columns: repeat(2, 80px);
grid-auto-rows: 60px;
width: 400px;
height: 300px;
place-content: space-between center;
}
This distributes grid rows along the block axis while centering the columns along the inline axis.
Centering a Small Grid
.grid-container {
display: grid;
grid-template-columns: 150px;
grid-template-rows: 100px;
min-height: 300px;
place-content: center;
}
This is useful when a small grid should be centered inside a larger container without changing the dimensions of its tracks.
Accessibility Considerations
The place-content property changes visual alignment but does not change the semantic structure or source order of HTML elements.
Maintain Logical Source Order
Keep the HTML source order meaningful, particularly for keyboard navigation and screen reader users.
Avoid Clipping Important Content
Some alignment settings can cause content to overflow its container. Ensure text and interactive controls remain visible and accessible.
Use Safe Alignment When Appropriate
.container {
place-content: safe center;
}
Safe alignment can help avoid certain overflow-related problems when content is larger than the available space.
Support Responsive Layouts
Test alignment at different viewport sizes. A layout that has extra space on a wide screen may have little or no extra space on a narrow screen.
Preserve Keyboard Access
Content alignment should not position interactive elements where they become difficult to reach or visually hidden.
Important Consideration
The property does not alter keyboard focus order or the reading order used by assistive technologies.
Common Mistakes
Confusing place-content With place-items
place-content aligns content groups, while place-items controls the default alignment of individual items.
Expecting Both Axes to Center Flex Items
.flex-container {
display: flex;
place-content: center;
}
In a single-line flex container, align-content has no effect. Use align-items: center to center items along the cross axis.
Forgetting Available Space
Content alignment may produce no visible change when the content already fills the available space.
Using Percentages
.container {
place-content: 50%;
}
Percentages are not valid alignment values for this property.
Using Commas
.container {
place-content: center, space-between;
}
Use spaces to separate the two alignment values, not commas.
Using Three Values
.container {
place-content: start center end;
}
The shorthand accepts at most two alignment components.
Assuming Fixed Tracks Stretch
In Grid, stretch distributes extra space to eligible auto-sized tracks. Fixed-size tracks do not automatically expand.
Confusing Logical and Physical Directions
The meaning of start and end depends on the writing mode and alignment axis.
Ignoring Flex Direction
In Flexbox, the main and cross axes change with flex-direction. Do not assume justify-content always controls horizontal alignment.
Overwriting Longhand Values
.container {
justify-content: space-between;
place-content: center;
}
The later shorthand resets both align-content and justify-content. In this example, both become center.
Using Unsupported Alignment Combinations
Not every alignment value is valid for both longhand properties. Check the grammar and the layout context when combining values.
Important Considerations
Keep the following points in mind when using place-content:
- It is a shorthand for
align-contentandjustify-content. - Its initial longhand values are both
normal. - The property is not inherited.
- It accepts one or two alignment components.
- The first component sets
align-content. - The second component sets
justify-content. - When one value is supplied, it normally applies to both longhand properties.
- For a single baseline-alignment value, the omitted second component becomes
start. - It can be used with CSS Grid and Flexbox.
- Its effects depend on the layout method and available space.
- In Grid, it controls alignment and distribution of the grid tracks.
- In Flexbox,
justify-contentcontrols main-axis distribution. - In Flexbox,
align-contentcontrols cross-axis distribution of flex lines. align-contenthas no effect in a single-line flex container.- It does not replace
align-itemsfor cross-axis alignment of individual flex items. - It does not replace
place-itemsfor alignment of individual grid items. - It supports positional values such as
start,end, andcenter. - It supports distribution values such as
space-between,space-around, andspace-evenly. stretchaffects eligible tracks or lines according to the layout context.- Baseline alignment is available only where the relevant longhand and layout context support it.
safeandunsafecan modify supported positional alignment values.- Percentages are not accepted as alignment values.
- Alignment components are separated by spaces, not commas.
- Logical alignment directions can change with writing mode and text direction.
- The shorthand resets both longhand properties when declared.
- Alignment changes do not alter HTML source order.
- Content should remain readable and accessible when the layout changes size.
- Test alignment in both wide and narrow containers.
Browser Support
The CSS place-content property is Widely available in modern browsers, including Chrome, Edge, Firefox, and Safari.
Support for the shorthand is well established, although individual alignment values and their behavior can depend on the layout method. Test advanced alignment combinations in the browsers your website supports.
For current compatibility information, visit Can I Use? and search for place-content.
Specifications
The place-content 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-content and justify-content.
For additional documentation and examples, consult MDN Web Docs.
