HTML and CSS · lesson 18 of 30 · free

Flexbox basics — HTML and CSS for kids

Flexbox lines boxes up in a row (or a column). Set display to flex on the container. justify-content then decides where the free space goes along the row: flex-start packs the boxes at the start, flex-end at the end, center in the middle with equal space on both sides, and space-between makes equal gaps between boxes with none at the ends. align-items lines boxes up across the row.

▶ Watch how it works

Got it? Practise ↓

Code tip

Find the free space — “free space = container − boxes; justify-content decides where it goes”

  1. Free space = container width − number of boxes × box width.
  2. flex-start: all free space after the last box; flex-end: all before the first box; center: half on each side.
  3. space-between: free space ÷ (boxes − 1) between each pair, none at the ends.

Use it for: Making menus, rows of cards and centred buttons.

Worked example: 💪 How much empty space (px) is left after the last box?
.row {
  display: flex;
  width: 190px;
  justify-content: flex-start;
}
Inside are 3 boxes, each 50px wide (no margins). → 40

  1. Free space = 190 − 3 × 50 = 40.
  2. flex-start packs the boxes at the start, so all 40 px is after the last box.

Check: 50 + 50 + 50 + 40 = 190 ✓

▶ Watch it animated

✏️ Practice

Work it out in your head or on paper, type the answer and press Check. Stuck? Press “Show me how”.

Right: 0 · Tried: 0

🏁 Lesson 18 test

20 questions. Check each answer, then go to the next one. Get 16 or more right to pass.

🏅 Sign in with Google to earn the 💪 Flexbox Flexer badge when you pass — and a certificate when you finish all 10 lessons of Part 2 · CSS. You can still take the test without signing in.

🖨️ CSS Worksheet: Flexbox Basics

✨ Free AI tutor

Ask the AI tutor about this lesson

Why does it work? When should you use it? Ask in English, मराठी or हिंदी.

Sign in with Google to ask Free — 20 questions a day.

👩‍🏫 HTML and CSS classes near you — online or at home

Prefer a real teacher? TalentJR teachers take live online classes anywhere in India and visit homes in selected cities. Tell us what you need and our team will call you with timings and fees.

Live online classesSmall groups or 1:1 with a teacher, from home, any city.
Teacher at homeA TalentJR teacher visits your home (selected cities).
At a centreClasses at a TalentJR partner centre near you, where available.
Badges, certificates & gifts A badge for every lesson you pass, a certificate for every part you finish, plus TalentJR Points for daily practice. Computer worksheets Flowcharts, block coding, spreadsheets and safe internet.