Skip to content
BENIBIX Learn

Responsive Web Design

Level 4 · Page layout

How one page fits a phone, a tablet and a wide screen. The viewport tag, media queries and breakpoints, and why phones come first.

Course contentsLesson 10 of 14

After this lesson you can

  • Add the viewport tag to a page
  • Write a media query for wider screens
  • Plan a layout mobile first

12 mincovers 5 glossary entries

Worth reading first: Flexbox, Grid and Position

How one page fits every screen

Responsive web design means one page that changes its layout to fit the screen. It rests on two parts. A viewport tag tells a phone to use its real width. Media queries then change the CSS at set widths. Without the tag, a phone may draw the page 980 pixels wide and shrink it.

The viewport tag is one line in the <head>: a meta tag with width=device-width. Phones once drew every page as if on a desktop, then shrank it so the text was tiny. The tag tells the phone the page was made for small screens, so it uses the screen's own width.

A media query is a block of CSS that only applies when a test is true. @media (min-width: 768px) holds rules for screens at least 768 pixels wide. Inside it, a list in one column can turn into a grid of three. A hidden menu can open out into a full bar.

Each width where the layout changes is called a breakpoint. There is no official list. The best breakpoints come from the content: widen the window slowly, and add one where the layout starts to look wrong. Most sites need two or three, not ten.

Mobile first is the usual way to write it. The plain CSS is for the smallest screen, with one column and large tap targets. Then min-width media queries add columns and extras as the screen grows. It is easier to add to a simple layout than to strip a big one down.

Flexible units do half the work before any media query runs. Widths in % or fr stretch with the window. Text in rem follows the reader's own text size. Pictures with max-width: 100% never spill out of their box. A page built that way needs fewer breakpoints.

People often test only by dragging a desktop window narrower. That misses the real thing: thumbs, slow networks and a screen held upright. Open the page on a real phone, or at least use the phone view in browser DevTools, before calling it done.

html
<meta name="viewport" content="width=device-width, initial-scale=1">

<style>
  .cards { display: grid; grid-template-columns: 1fr; gap: 1rem; }

  @media (min-width: 768px) {
    .cards { grid-template-columns: repeat(3, 1fr); }
  }
</style>
One column on a phone. At 768 pixels and wider, the same cards fall into three columns.
Same HTML, same cards. The media query changes the layout once the screen is wide enough.

Worked example

Jack's menu is tiny on phones

Jack's cafe menu looks fine on his laptop. On a phone, the text is so small that 7 in 10 visitors leave within a few seconds.

The page had no viewport tag. He adds the one line and a media query at 600 pixels, and the menu now shows as one readable column.

The words for this lesson5

Check yourself

What happens on a phone if a page has no viewport tag?

Finished this lesson?

Marking it complete also marks its 5 glossary entries learned, which updates your roadmap and your saved page. 0 are already marked.