Set the space between the items in a row, where the row sits them, and how they line up across it.
A menu bar with the logo on the left and the links on the right is one flex row with three properties.
A flex row puts items side by side, but they all bunch at one end. Three more properties on the same box say where the items go, and how much space sits between them.
Make your prediction first. Help opens once you've locked it in.
<style>
.bar {
display: flex;
justify-content: space-between;
align-items: center;
gap: 20px;
height: 100px;
border: 2px solid navy;
}
</style>
<div class="bar">
<h2>Robotics Club</h2>
<a href="https://example.com/events">Events</a>
<a href="https://example.com/join">Join</a>
</div>
justify-content, align-items and gap are new, and all three go on the box with display: flex. Read the code. Where do the three items sit along the bar?
Compare the bar with your prediction. Then change space-between to center, then to flex-end, and watch the whole group move. Change align-items to flex-start, then flex-end, and watch the items move up and down.
| Code | What it does | Why |
|---|---|---|
display: flex; |
Puts the items in a row | As in the last lesson, it goes on the box that holds the items |
justify-content: space-between; |
Sends the first item to the start, the last to the end, and shares the leftover space between them | justify-content works along the row, in the direction the items run. Other values: flex-start, center, flex-end |
align-items: center; |
Centres each item across the row, halfway down the bar | align-items works across the row, at right angles to it. The bar is 100px tall, so there is room to see it |
gap: 20px; |
Puts at least 20px between neighbouring items | gap is space between items only, not at the ends. justify-content then shares out whatever room is left |
height: 100px; |
Makes the bar taller than its items | Without spare room across the row, align-items has nothing to show |
<style>
.bar {
display: flex;
justify-content: space-between;
align-items: center;
gap: 20px;
height: 100px;
border: 2px solid navy;
}
</style>
<div class="bar">
<h2>Robotics Club</h2>
<a href="https://example.com/events">Events</a>
<a href="https://example.com/join">Join</a>
</div>
<style>
.bar {
display: flex;
justify-content: space-between;
align-items: center;
gap: 20px;
height: 100px;
border: 2px solid navy;
}
</style>
<div class="bar">
<h2>Robotics Club</h2>
<a href="https://example.com/events">Events</a>
<a href="https://example.com/join">Join</a>
</div>
Which line does which job?
Look at the cards.
The items are at the top of the bar.
The row is right this time.
Match each line with what it does to a flex row.
The three items should have 20px between them, but they touch, and there is no error. Click the line that causes it.
Put 24px between the three menu links.
Space between items is a job for the row, not for each link.
Add gap: 24px; to the .menu rule.

Move the group of links to the middle of the row.
Where the group of links sits along the row: justify-content.
Add justify-content: center; to the .menu rule.

The star and the club name sit at the top of the bar. Centre them up and down.
The star and the name should line up across the bar. Which property works across the row?
Add align-items: center; to the .bar rule.

Put 24px between the menu links.
This ticks when your page has all of the above.
Centre the menu links in their row.
This ticks when your page has all of the above.
Centre the star and the name up and down in the bar.
This ticks when your page has all of the above.
Here is a row of three items with the margin version.
<style>
.strip {
display: flex;
border: 2px solid navy;
}
.item {
margin: 10px;
padding: 10px;
border: 1px solid gray;
}
</style>
<div class="strip">
<div class="item">One</div>
<div class="item">Two</div>
<div class="item">Three</div>
</div>
The club's header has a name and a menu, one above the other. Make the header a row with the name at the left and the menu at the right, lined up across the bar.
There are two items inside the header: the h1 and the nav that holds the links. The row goes on the header.
In .bar add display: flex;, then the property that puts the first item at one end and the last at the other.
Then align-items: center; so the title and the links line up across the bar.

Put the club name on the left and the menu on the right of the header.
This ticks when your page has all of the above.
Students space a flex row with gap, place its items with justify-content and line them up with align-items, and find out that these go on the row and work in two directions. About 40 minutes.
Open the teacher guide: answers, solutions, slides and a worksheet.
Do the Make task yourself in the playground (about 4 minutes).
A flex row is a box with display: flex: its children (the items) sit side by side. justify-content works along the row, the way the items run. align-items works across it, at right angles, so with a row it means up and down. The common slip is to swap them. All three properties go on the box that holds the items, never on the items.
Telling along from across. Ask which way the row runs, and which property works in that direction, before telling them.
Stretch: Put the menu in a second flex row of its own, inside the nav, and give it a gap. Then try space-around and space-evenly beside space-between.
Support: Give students the Run page and ask them only to change the word after justify-content, five times, and say what each did.
Next lesson makes a row wrap when it runs out of room, so it fits a phone as well as a laptop. Class idea: look at the menu bars of three websites and decide which values of justify-content and align-items they use.