Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / CSS

CSS property `justify-items`

`justify-items` establishes the default justify-self value for grid items on the inline axis of their grid areas.

Version: CSS modules; captured CSSWG editor index includes draft and obsolete features requiring review

Syntax

normal | stretch | <baseline-position> | <overflow-position>? [ <self-position> | left | right ] | legacy | legacy && [ left | right | center ] | anchor-center

justify-items establishes the default justify-self value for grid items on the inline axis of their grid areas.

The example moves a real grid child from start to center and measures its x coordinate.

Grammar: normal | stretch | <baseline-position> | <overflow-position>? [ <self-position> | left | right ] | legacy | legacy && [ left | right | center ] | anchor-center.

A child justify-self overrides this default; in flexbox, justify-items does not position flex items.

Examples

<!doctype html><html lang="en"><meta charset="utf-8"><title>CKTIS CSS example</title><body><pre id="result"></pre><script>const g=document.createElement("div"),x=document.createElement("i");document.body.prepend(g);g.append(x);g.style.cssText="display:grid;width:100px;height:40px;grid-template-columns:100px";x.style.cssText="width:20px;height:10px";const a=g.getBoundingClientRect();g.style.justifyItems="start";const x0=Math.round(x.getBoundingClientRect().left-a.left);g.style.justifyItems="center";const x1=Math.round(x.getBoundingClientRect().left-a.left);document.querySelector("#result").textContent="child-x="+x0+"->"+x1+"; computed="+getComputedStyle(g).justifyItems;</script></body></html>

Result

child-x=0->40; computed=center

The example was executed locally in an isolated, network-free Chrome session; the result comes from the browser CSS API.

Sources