CSS Reference ยท Flexbox
The place-content property
Reference for the CSS place-content shorthand: set align-content and justify-content together to center or distribute a grid or flex layout, with examples.
The place-content property is a shorthand for align-content and justify-content. It decides how the whole set of tracks (in a grid) or lines (in a wrapped flex container) is positioned and spaced inside the container when there is spare room.
One value is applied to both axes; two values give the block-axis value first, then the inline-axis value.
.grid { place-content: center; } .grid { place-content: start space-between; }
Try it
The four fixed-size tracks use less space than the container offers. place-content: center moves the whole block of tracks to the middle, vertically and horizontally.
Syntax
place-content: <'align-content'> <'justify-content'>?
- Initial value:
normal(for both) - Applies to: block containers, flex containers and grid containers
- Inherited: no
- Animatable: no
- Computed value: as specified for the longhands
Values
| Value | Description |
|---|---|
start, end, center |
Packs the tracks or lines at the start, end or middle. |
flex-start, flex-end |
Like start and end, in flex layout. |
space-between |
Pushes the first and last tracks to the edges and spreads the rest evenly. |
space-around |
Equal space around each track, so edges get half the inner gap. |
space-evenly |
Identical space between all tracks and at both edges. |
stretch |
Enlarges auto-sized tracks or lines to fill the container. |
normal |
Default; behaves like stretch in grid and flex layout. |
Usage notes
- Needs free space. If the tracks already fill the container (for example
1frcolumns), there is nothing to distribute and nothing visibly changes. - Different from
place-items.place-contentmoves the tracks as a group;place-itemsaligns each item inside its own cell. - Single-line flex containers.
align-contentis ignored there, so the first value has no effect untilflex-wrap: wrapcreates several lines. - One value means both.
place-content: centeris the quickest way to center a fixed-size grid. Some values, such asspace-between, are valid on both axes.
Browser support
Supported in all current browsers for grid and flex containers.
Related
align-contentโ block-axis partjustify-contentโ inline-axis partplace-itemsโ shorthand for item alignment- Lesson: Grid Alignment