Definition
The place-self CSS property is a shorthand property that combines the align-self and justify-self properties. It is used in CSS Grid and CSS Flexbox layouts to control the alignment and positioning of an individual grid or flex item within its container, both horizontally and vertically.
The place-self property accepts two values, representing the alignment and positioning of the item along the block and inline axes, respectively. The values can be specified in any order, separated by a space.
Here are some commonly used values:
-
start: Aligns the item to the start edge of the container. -
end: Aligns the item to the end edge of the container. -
center: Centers the item both horizontally and vertically within its cell or space. -
stretch: Stretches the item to fill the available space in its cell or space. -
baseline: Aligns the item along its baseline.
Here’s an example in a grid container:
.item {
place-self: center end;
}
In this example, the .item class uses place-self: center end;. This centers the item both horizontally and vertically within its cell or space, and aligns it to the end edge of the container.
You can mix and match the available values of place-self to achieve the desired alignment and positioning of an individual grid or flex item within its container. It provides a convenient way to set both the block and inline alignment properties at once, reducing the need for separate align-self and justify-self declarations.
The place-self property is particularly useful when working with CSS Grid and Flexbox layouts, allowing you to easily control the alignment and positioning of individual items, improving the overall design and layout of your webpage.
Syntax
.card {
display: grid;
}
.card__cta {
place-self: center;
}
place-self 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). -
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. -
auto: inherit the parent container setting unless overridden.
Practical Examples
.pricing {
display: grid;
grid-template-columns: repeat(3, minmax(0, 1fr));
justify-items: center;
gap: 2rem;
}
.pricing__cta {
place-self: center;
}
Targeted alignment keeps each call-to-action centered without disturbing sibling cards.
Inherited alignment
Override with place-self: 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">Inherited 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; align-items: start; justify-items: start;">
<button class="rounded-full bg-slate-900 px-4 py-2 text-sm font-semibold text-white">Default</button>
<button class="rounded-full bg-slate-100 px-4 py-2 text-sm font-semibold text-slate-700">Also start</button>
</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">Override with place-self: 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; align-items: start; justify-items: start;">
<button class="rounded-full bg-slate-900 px-4 py-2 text-sm font-semibold text-white">Default</button>
<button class="rounded-full bg-sky-500 px-4 py-2 text-sm font-semibold text-white" style="place-self: center;">Centered</button>
</div>
</div>
</div> Tips & Best Practices
- Align on the container first, then reach for
*-selfoverrides only when a child needs unique treatment. - Prefer logical keywords (
start,end) over physical directions for better localisation. - Combine alignment with
gapto manage spacing without extra wrapper elements. - Use
autoto fall back to the container alignment and reduce redundant declarations.
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
-
gapfor consistent spacing between tracks or items. -
justify-content,align-items, andplace-contentto coordinate both layout axes. -
flex-directionandgrid-auto-flowinfluence which axis is treated as main vs. cross.