Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / CSS

gap — CSS property

`gap` sets row and column gutters in grid, flex, and multi-column layout.

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

Syntax

<'row-gap'> <'column-gap'>?

gap sets row and column gutters in grid, flex, and multi-column layout.

The example uses a wrapping flex container and measures the horizontal and vertical space between items separately.

The accepted grammar is <'row-gap'> <'column-gap'>?; global values still participate in the cascade.

In flexbox, the meaning of row-gap and column-gap follows flex-direction; percentages can be cyclic when the container size depends on content.

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></i><i></i><i></i><i></i></div><pre id="result"></pre>';const g=document.querySelector("#g");g.style.cssText="display:flex;flex-wrap:wrap;width:44px;gap:8px 4px";for(const x of g.children)x.style.cssText="width:20px;height:10px";const a=g.children[0].getBoundingClientRect(),b=g.children[1].getBoundingClientRect(),c=g.children[2].getBoundingClientRect();document.querySelector("#result").textContent="column-gap="+Math.round(b.left-a.right)+"; row-gap="+Math.round(c.top-a.bottom)+"; computed="+getComputedStyle(g).gap;
</script></body></html>

Result

column-gap=4; row-gap=8; computed=8px 4px

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

Sources