gap
W3C CSS Snapshot 2026
Add spacing between items and between flex lines. The shorthand sets row-gap followed by column-gap.
On this page
Syntax and values
| Value or syntax | What it does |
|---|---|
normal | The initial gap in a flex layout resolves to zero. |
12px / 1rem | A single nonnegative length applies to both gaps. |
8px 20px | Sets row-gap to 8px and column-gap to 20px. In a row flex container these separate lines and items respectively. |
5% | Percentages refer to the container size along the relevant axis. In flex layout an indefinite size can make the percentage gap resolve to zero. |
Try the example
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>gap example</title>
<style>
.layout { display: flex; width: min(100%, 320px); border: 2px solid teal; box-sizing: border-box; }
.layout > div { padding: 8px 12px; background: #def5f5; color: #123; border: 1px solid #81b9b5; box-sizing: border-box; }
.layout { flex-wrap: wrap; gap: 8px 20px; }
.layout > div { flex: 0 0 42%; }
</style>
</head>
<body>
<div class="layout">
<div class="first">A</div>
<div class="second">B</div>
<div>C</div>
</div>
</body>
</html>
What to expect A and B have a wider gap between them than the two lines do. Try gap: 16px.