Command Palette

Search for a command to run...

Hectal
Back to the lesson: Topic 7.4 — Wrapping and Gaps
CSS · Example 3 of 4

order changes what you see, not what you Tab through

C (order: -1) jumps to the front, B (order: 2) to the back; A and D share order: 0 and keep their HTML order. Click A and press Tab a few times: focus goes A, B, C, D, jumping around the screen.

flex-wrap: wrap lets items break onto new lines instead of shrinking, gap puts fixed space between items and lines without touching the outer edges, and order changes only the visual position of an item, never its reading or Tab order.

Change the code and press Run (Ctrl+Enter). Predict what will happen first, then break it on purpose and read what changes. Your edits are saved and match the lesson page.

Ready for more? This phase has 6 hands-on exercises with automatic checks.

Practice questions

Write the code in the editor, run it, then open the model answer to compare.

01

Make a list of tags (<span class="tag">) wrap onto new lines with 8px between tags and 6px between lines.

02

Write CSS for a row of items that wraps, with 16px gaps, where each item is at least 200px and grows to fill the line.

03

A product card has <img> then <h2> in the HTML. Show the heading above the image visually. Is order a good idea here?

Explain it without notes

01

What is the difference between flex-wrap: nowrap and wrap when items don't fit?

02

Why is gap better than margins for spacing flex items?

03

What does order change, and what doesn't it change?

04

How can you make a responsive row of cards with Flexbox and no media queries, and what is its weakness?

order changes what you see, not what you Tab through

Preview

Press Run to see the page.

Console

Nothing logged yet.

Expected console output

HTML and Tab order: A B C D
Visual order:       C A D B
order values: 0, 2, -1, 0