Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / CSS

grid — CSS property

`grid` defines the explicit grid, auto-placement, and track sizing in a grid formatting context.

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

Syntax

<'grid-template'> | <'grid-template-rows'> / [ auto-flow && dense? ] <'grid-auto-columns'>? | [ auto-flow && dense? ] <'grid-auto-rows'>? / <'grid-template-columns'>

grid defines the explicit grid, auto-placement, and track sizing in a grid formatting context.

Use it when track size or item placement must follow explicit grid lines; the example reports the resulting item coordinates and dimensions.

The accepted grammar is <'grid-template'> | <'grid-template-rows'> / [ auto-flow && dense? ] <'grid-auto-columns'>? | [ auto-flow && dense? ] <'grid-auto-rows'>? / <'grid-template-columns'>; global values still participate in the cascade.

Line numbers start at 1, negative numbers count from the end of the explicit grid, and shorthands can reset auto-placement settings.

Examples

<!doctype html>
<html lang="en"><meta charset="utf-8"><title>CKTIS CSS reference example</title>
<body><div class="probe">probe</div><pre id="result"></pre><script>
document.body.innerHTML='<div id="g"><i id="a"></i><i></i></div><pre id="result"></pre>';const g=document.querySelector("#g");g.style.display="grid";g.style.grid=`"a b" 20px / 30px 40px`;const s=getComputedStyle(g);document.querySelector("#result").textContent="columns="+s.gridTemplateColumns+"; rows="+s.gridTemplateRows+"; areas="+s.gridTemplateAreas;
</script></body></html>

Result

columns=30px 40px; rows=20px; areas="a b"

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

Sources