Definition
The place-content
CSS property is a shorthand property that combines the align-content
and justify-content
properties. It is used in CSS Grid and CSS Flexbox layouts to control the alignment and positioning of the grid or flex items within their container both horizontally and vertically.
The place-content
property accepts various values that can be specified in any order, separated by a space:
-
start
: Aligns items to the start edge of the container. -
end
: Aligns items to the end edge of the container. -
center
: Centers items along both the horizontal and vertical axes. -
stretch
: Stretches items to fill the entire container. -
space-between
: Distributes items evenly along the main axis, with the first item at the start edge and the last item at the end edge. -
space-around
: Distributes items evenly along the main axis, with equal space before the first item and after the last item. -
space-evenly
: Distributes items evenly along the main axis, with equal space between all items.
Here’s an example in a flex container:
.container {
display: flex;
place-content: center space-between;
}
In this example, the .container
class sets a flex container and uses place-content: center space-between;
. This aligns the flex items both horizontally and vertically at the center of the container, with equal space between the items.
You can mix and match the available values of place-content
to achieve the desired alignment and positioning of the grid or flex items within their container. It provides a convenient way to set both the horizontal and vertical alignment properties at once, reducing the need for separate align-content
and justify-content
declarations.
The place-content
property is particularly useful when working with CSS Grid and Flexbox layouts, allowing you to easily control the positioning and alignment of items within their container, improving the overall design and layout of your webpage.
Syntax
.layout {
display: grid;
grid-auto-rows: minmax(0, 1fr);
place-content: center;
}
place-content
works across flexbox and grid layouts to position tracks or individual items along the main or cross axis.
Values
-
start
/end
: align content to the logical start or end edge (writing-mode aware). -
space-between
/space-around
/space-evenly
: distribute free space between tracks (main axis). -
center
: center items or tracks along the axis. -
stretch
: expand items to fill the available space when allowed. -
baseline
: line up first baselines for tidy typography. -
safe
/unsafe
: let the browser avoid or allow overflow when centering could clip content.
Practical Examples
.pricing {
display: grid;
grid-template-columns: repeat(3, minmax(0, 1fr));
place-content: center;
gap: 2rem;
}
Center-aligned tracks keep pricing cards balanced across breakpoints.
Default alignment
With place-content: center
<div class="grid gap-4 sm:grid-cols-2">
<div class="space-y-3 rounded-lg border border-slate-200 bg-white p-4 shadow-sm">
<p class="text-xs font-semibold uppercase tracking-wide text-slate-500">Default alignment</p>
<div class="grid h-48 gap-3 rounded-md border border-dashed border-slate-300 bg-slate-50 p-3" style="display: grid; grid-auto-rows: minmax(0, 1fr);">
<span class="flex h-12 w-12 items-center justify-center rounded-full bg-slate-900 text-white">A</span>
<span class="flex h-12 w-12 items-center justify-center rounded-full bg-slate-200 text-slate-700">B</span>
<span class="flex h-12 w-12 items-center justify-center rounded-full bg-slate-200 text-slate-700">C</span>
</div>
</div>
<div class="space-y-3 rounded-lg border border-slate-200 bg-white p-4 shadow-sm">
<p class="text-xs font-semibold uppercase tracking-wide text-slate-500">With place-content: center</p>
<div class="grid h-48 gap-3 rounded-md border border-dashed border-slate-300 bg-slate-50 p-3" style="display: grid; grid-auto-rows: minmax(0, 1fr); place-content: center;">
<span class="flex h-12 w-12 items-center justify-center rounded-full bg-slate-900 text-white">A</span>
<span class="flex h-12 w-12 items-center justify-center rounded-full bg-slate-200 text-slate-700">B</span>
<span class="flex h-12 w-12 items-center justify-center rounded-full bg-slate-200 text-slate-700">C</span>
</div>
</div>
</div>
Tips & Best Practices
- Align on the container first, then reach for
*-self
overrides only when a child needs unique treatment. - Prefer logical keywords (
start
,end
) over physical directions for better localisation. - Combine alignment with
gap
to manage spacing without extra wrapper elements. - Pair with
justify-items
/align-items
to fine-tune both axes in grid layouts.
Accessibility & UX Notes
Predictable alignment lowers cognitive load and lets keyboard users tab through content without unexpected jumps. Maintain visible focus indicators and ensure stretched components still provide generous hit areas.
Browser Support
align-*
and justify-*
properties are well supported. place-*
shorthands require Chrome 59+, Edge 79+, Firefox 66+, Safari 12.1+.
Related
-
gap
for consistent spacing between tracks or items. -
justify-content
,align-items
, andplace-content
to coordinate both layout axes. -
flex-direction
andgrid-auto-flow
influence which axis is treated as main vs. cross.