Home › Learn › HTML and CSS › Layout

Flexbox: a row of items

Lesson 12 of 20. display: flex, gap, and flex-wrap.

display: flex on a container lays its children out in a row. gap: 12px spaces them. flex-wrap: wrap lets them move to the next line when they run out of room; without it they shrink. flex-direction: column stacks them vertically instead.

Flexbox is the tool for one-dimensional layout: a toolbar, a row of cards, a navigation bar, a label next to a field. It replaced floats and inline-block tricks for good reason: it handles sizes and spacing for you.

.row { display: flex; gap: 12px; flex-wrap: wrap; }

Your task

Turn .row into a flex container with a 12px gap and wrapping enabled. Do not size the items.

Hint 1

display: flex;

Hint 2

gap: 12px; flex-wrap: wrap;

Show the solution
<!doctype html>
<html>
<head>
<style>
.item { padding: 12px; background: rgb(232, 239, 255); }
.row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}
</style>
</head>
<body>
<div class="row">
  <div class="item">One</div>
  <div class="item">Two</div>
  <div class="item">Three</div>
</div>
</body>
</html>
Preview

    Renders in the preview as you type; the checks read the rendered page.