Skip to content
engineering workbench.by StudyPort Academy
Learning path
Advanced18 minLESSON 13 / 16

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.

Base rules and queries
WidthWhat matchesArrangement
Under 520pxOnly the base ruleA column
520px and upThe first queryA row
760px and upBoth queriesA 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.

04

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.

Opening editor…
LIVE PREVIEW
Console 0

Your console output appears here.

Saved on this deviceJavaScript · ES2022

EXPECTED CONSOLE OUTPUT

column
3
Field notes
520px

Hints 0/2

    Use all hints or make 3 failed runs (0/3).

    05

    Free sandbox

    Edit the HTML and CSS. The JavaScript tab can read the result. This draft is saved separately.

    Opening editor…
    LIVE PREVIEW
    Console 0

    Your console output appears here.

    Saved on this deviceJavaScript · ES2022
    06

    Quiz

    A quick check for understanding. Retry as often as you like; your learning path stays open.

    01What should the unqueried CSS describe?
    02What does the viewport meta element change for a query?

    Ready to call this one understood?

    Mark this lesson complete to earn 200 XP. You can always revisit it.

    Sign in to save progress
    Next lesson