HTML and CSS lesson 15: Flexbox: boxes in a row
UK version. UK school years and UK spelling. · US version of this lesson
display: flex on a container lines up the boxes inside it in a row; flex-direction: column stacks them and gap sets the space between. A complete 40-minute HTML and CSS lesson for beginners (Year 7, KS3), from Unit 5: Boxes and layout. You build real web pages right here in your browser – nothing to install.
- Time
- 40 minutes + 20 min homework
- Year
- Year 7, KS3 (ages 11–12)
- You need
- A computer or tablet, paper and a pencil
- Marked
- Instantly, with explanations
For parents: how to use this lesson
You don't need to know HTML yourself. The lesson explains each step on screen, the way Mr Babbage, our Head of Computing, likes it: a worked example first, then a go for your child. When your child builds a page, the browser draws it straight away and Classfern marks it with a checklist.
- Read what your child will learn together.
- Press Start the lesson below. Sit with your child for the teaching and the worked example (about 15 minutes): ask them to point at each tag and say what it does.
- Let them do the practice on their own. If a page doesn't look right, the checklist says what is missing – let them find the mistake before you help.
- Finish with the exit questions and the talk question: “Where have you seen boxes in a row on websites you use?”
- Later that day or the next day: the homework (20 minutes), then a practice test.
Watch out for
display: flexgoes on each box. It goes on the parent that holds them.gapadds space at the edges too. Only between items.
Miss Lovelace's tip for home: ask your child to change one thing on their page – a word, a colour, a size – and predict what will happen before they look. Predicting first is how programmers learn fastest.
What your child will learn
We are learning to put boxes in a row with flexbox.
Success looks like
- I can put boxes in a row with flexbox.
- I can stack them in a column.
- I can set the space between items with
gap.
Key words
flexbox · flex container · flex item · flex-direction · row · column · gap
What to have ready
- A device with a web browser (pages are built and checked right in the browser – nothing to install)
- Paper for planning and sketching
- A keyboard helps for typing code (a tablet works too)
The big ideas (for the adult)
Normally blocks such as <div> stack one under another. Flexbox changes that: put display: flex; on the CONTAINER (the parent) and the boxes inside it line up side by side in a row.
flex-direction: column; turns the row into a column. gap: 20px; puts 20px between the items – but not at the edges. A menu bar is a classic use: nav { display: flex; gap: 16px; } puts the links in a row.
The most common mistake is putting display: flex on the items instead of the container. Another is a misspelt value: display: flexbox or flex-direction: columns are ignored, so nothing changes.
Worked example: a menu bar
CSS:
nav { display: flex; gap: 16px; }HTML:
<nav> <a href="index.html">Home</a> <a href="news.html">News</a> <a href="contact.html">Contact</a> </nav>
The lesson, step by step
| Part | Time | How it is checked |
|---|---|---|
| Starter | 5 min | Marked by Classfern |
| Learn | 8 min | Read, watch and talk |
| See it | 7 min | Marked by Classfern |
| Practise | 15 min | Marked by Classfern |
| Check and reflect | 5 min | Marked by Classfern + self-check |
The lesson
It runs here on the page. No sign-up and no names – nothing you type is sent anywhere. Each visit picks a new mix of questions.
Homework
20 minutes: predict what the browser will do, build or fix a short page, and check the key ideas – then a short reflection. New questions every time, all marked instantly.
Practice tests
- The box model and flexbox test12 questions · marked instantly
- Mixed HTML and CSS test20 questions · marked instantly
- Mixed HTML and CSS test20 questions · marked instantly
All KS3 computing practice tests · All 20 HTML and CSS lessons
Curriculum
National curriculum in England, computing, key stage 3: pupils should be taught to use 2 or more programming languages, at least one of which is textual, to solve a variety of computational problems; make appropriate use of data structures [for example, lists, tables or arrays]; design and develop modular programs that use procedures or functions; and to create, reuse, revise and repurpose digital artefacts for a given audience, with attention to trustworthiness, design and usability.
Contains public sector information licensed under the Open Government Licence v3.0.
Our lessons and questions are our own. They are not written or endorsed by any government department, testing agency or exam board. HTML and CSS are open web standards; Classfern is not affiliated with the organisations that publish them.