Responsive design and media queries
Change a control, or edit the CSS. The preview uses that same CSS.
Only the base rules match. Drag wider.
Numeric changes ease so you can watch them.
Dragging the width did not swap in a second HTML file. The base column stayed in the CSS, and a min-width query added the row only while the frame was wide enough for that query to match. The highlighted block was the query that had turned on.
+Go deeper
The narrow layout is the base
Write the narrow arrangement first, with no query. keeps one document. The wider arrangement is added later. or can be that base. A column of cards is a complete page before any query exists.
A query is a condition
A applies the rules inside it only while the condition is true. min-width of 520px means "at this width and wider." A second query at 760px can add more, and both can match at once. The highlighted one in the playground is the widest query that currently matches.
The viewport is the width that matters
The is the visible area the query measures. The meta element from the document-structure lesson is what makes a phone use its own width. The slider in the playground is that width for the frame. Dragging it is the condition changing, not a new document.
| Width | What matches | Arrangement |
|---|---|---|
| Under 520px | Only the base rule | A column |
| 520px and up | The first query | A row |
| 760px and up | Both queries | A row with a larger gap |
Breakpoints follow the content
Add a query when the layout actually needs it, not because a phone has a famous width. A long word, a fixed track, or an image wider than the parent will overflow even when the query matches. Fix the item, then add the query.
Drag until the rule lights up
Start narrow and confirm the column. Drag past 520px and watch the row appear and the query highlight. Drag back and the highlight leaves. The HTML did not change.
Guided challenge
Responsive design and media queries
The base style is a column. The script logs row, which is what the query adds only when it matches. Read the style attribute for the base direction.
Your console output appears here.
EXPECTED CONSOLE OUTPUT
column 3 Field notes 520px
Hints 0/2
Use all hints or make 3 failed runs (0/3).
Free sandbox
Edit the HTML and CSS. The JavaScript tab can read the result. This draft is saved separately.
Your console output appears here.
Quiz
A quick check for understanding. Retry as often as you like; your learning path stays open.
Ready to call this one understood?
Mark this lesson complete to earn 200 XP. You can always revisit it.