Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / CSS

CSS property `place-items`

`place-items` sets the container’s default self-alignment for its children in one declaration: the first value goes to `align-items`, and the optional second goes to `justify-items`.

Version: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, per-example verification still required

Syntax

<'align-items'> <'justify-items'>?

place-items sets the container’s default self-alignment for its children in one declaration: the first value goes to align-items, and the optional second goes to justify-items.

The example uses one grid cell spanning the whole container: end start puts a small item at the block-axis end and inline-axis start, while a single center centers it on both axes.

Grammar: <'align-items'> <'justify-items'>?.

When the second value is omitted, the first is copied. The shorthand aligns items inside their areas rather than distributing tracks; in flex layout justify-items does not control placement on the main axis. stretch can change an auto-sized child, and normal resolves according to the layout model.

Examples

<!doctype html><meta charset="utf-8"><style>html,body{margin:0}.grid{position:absolute;top:0;width:200px;height:120px;display:grid;grid-template:120px/200px}.grid i{width:40px;height:20px}</style><div id="pair" class="grid" style="left:0;place-items:end start"><i></i></div><div id="single" class="grid" style="left:300px;place-items:center"><i></i></div><pre id="result"></pre><script>const offset=box=>{const a=box.getBoundingClientRect(),b=box.firstElementChild.getBoundingClientRect();return[Math.round(b.left-a.left),Math.round(b.top-a.top)]},a=offset(pair),b=offset(single),x=getComputedStyle(pair),y=getComputedStyle(single);if(a.join(',')!=='0,100'||b.join(',')!=='80,50'||x.alignItems!=='end'||x.justifyItems!=='start'||y.alignItems!=='center'||y.justifyItems!=='center')throw new Error('place-items mismatch');result.textContent='pair='+a.join(',')+' '+x.alignItems+'/'+x.justifyItems+'; single='+b.join(',')+' '+y.alignItems+'/'+y.justifyItems;</script>

Result

pair=0,100 end/start; single=80,50 center/center

The example uses one grid cell spanning the whole container: `end start` puts a small item at the block-axis end and inline-axis start, while a single `center` centers it on both axes.

Sources