Flex sizing and grid placement

W3C CSS Snapshot 2026

Set the starting size of a flex item and control how it grows or shrinks. Then use grid lines to place items across tracks.

On this page

Set a starting size with flex-basis

flex-basis sets the starting size along the main axis. The browser can adjust it afterward using grow and shrink. Here both are zero.

How to try it Save this example as a new .html file, then open it in your browser. After a change, save and reload.

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Set a starting size with flex-basis</title>
  <style>
.row { display: flex; flex-wrap: wrap; gap: 4px; }
.row > div { flex: 0 0 72px; box-sizing: border-box; }
.row > div { background: #d8efeb; padding: 6px; border: 1px solid teal; }
  </style>
</head>
<body>
<div class="row"><div>Pen</div><div>Notebook</div><div>Folder</div></div>
</body>
</html>

What to expect Each item’s width is 72px, including its padding and border.

Share available space with flex-grow

flex-grow distributes leftover main-axis space. With equal bases and no size constraints, a grow factor of 2 receives twice the extra space of a factor of 1.

How to try it Save this example as a new .html file, then open it in your browser. After a change, save and reload.

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Share available space with flex-grow</title>
  <style>
.row { display: flex; max-width: 330px; }
.row > div { flex: 1 1 56px; }
.row > :nth-child(2) { flex-grow: 2; }
.row > div { background: #d8efeb; padding: 6px; border: 1px solid teal; }
  </style>
</head>
<body>
<div class="row"><div>Pen</div><div>Notebook</div><div>Folder</div></div>
</body>
</html>

What to expect Notebook receives more extra width. Set its grow factor to 1 to make the widths equal.

Make items fit with flex-shrink

When items need more room than is available, the browser shrinks each item using flex-shrink weighted by its base size. Zero keeps an item out of that calculation. A minimum width can limit shrinking.

How to try it Save this example as a new .html file, then open it in your browser. After a change, save and reload.

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Make items fit with flex-shrink</title>
  <style>
.row { display: flex; max-width: 250px; }
.row > div { flex: 0 1 100px; box-sizing: border-box; min-width: 0; overflow-wrap: anywhere; }
.row > :nth-child(2) { flex-shrink: 0; }
.row > div { background: #d8efeb; padding: 6px; border: 1px solid teal; }
  </style>
</head>
<body>
<div class="row"><div>Pen</div><div>Notebook</div><div>Folder</div></div>
</body>
</html>

What to expect Notebook keeps its starting width. Give it flex-shrink: 1 to make all three shrink evenly.

Span columns with grid-column

Three columns have four vertical lines along their edges. grid-column: 1 / 3 starts at line 1 and ends at line 3, so it covers two columns.

How to try it Save this example as a new .html file, then open it in your browser. After a change, save and reload.

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Span columns with grid-column</title>
  <style>
.row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; }
.row > :first-child { grid-column: 1 / 3; }
.row > div { background: #d8efeb; padding: 6px; border: 1px solid teal; }
  </style>
</head>
<body>
<div class="row"><div>Pen</div><div>Notebook</div><div>Folder</div></div>
</body>
</html>

What to expect Pen spans two columns. Notebook fills the third.

Span rows with grid-row

Row lines mark the top and bottom edge of each row. grid-row: 1 / span 2 starts at the first line and takes up two rows.

How to try it Save this example as a new .html file, then open it in your browser. After a change, save and reload.

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Span rows with grid-row</title>
  <style>
.row { display: grid; grid-template-columns: 1fr 1fr; grid-auto-rows: 40px; gap: 4px; }
.row > :first-child { grid-column: 1; grid-row: 1 / span 2; }
.row > div { background: #d8efeb; padding: 6px; border: 1px solid teal; }
  </style>
</head>
<body>
<div class="row"><div>Pen</div><div>Notebook</div><div>Folder</div></div>
</body>
</html>

What to expect Pen spans two rows on the left. Notebook and Folder stack on the right.

Official references