Web Design for Developers / Module 07

Module 7: Layout and Responsive Design

Fix a form that breaks on a phone, then give every page margins, a content width, grids that line up, and breakpoints chosen by the content.

This is the sign-up page of Stashling, the course’s sample site, as Module 6 left it, on a phone screen 390 pixels wide.

Figure 1: the sign-up form at 390 pixels. The fields and the submit button are past the right edge.

A reader would say the form doesn’t fit. The heading is cut off and every field runs off the screen. The button that sends the form is out of sight, so a visitor has to scroll sideways to find it.

This module is about layout, meaning where each block sits and how wide it is at every screen width. Responsive design is one page whose layout adapts to the width it is shown at. The module fixes the form, then gives all four pages one set of margins and widths, cards that line up, and a table that scrolls inside its own box.

After this module, you can:

  • find what makes a page wider than a phone, and fix it so the page fits a screen 320 CSS pixels wide
  • give every page the same side margins and a maximum width for its content, set as tokens
  • choose between Grid and Flexbox by asking who should decide the sizes, and make the parts of side-by-side cards line up
  • choose the width where a layout changes from its content, and let a form change its layout by its own width
  • keep the order that keyboard and screen reader users meet the same as the order on screen, and say which claims about how people scan a page have evidence

To follow along, start from the module-06 folder of the course repository, github.com/vespaiach/web-design-course. Open signup.html in Chrome, open DevTools and turn on device mode with a width of 390.

A form that works on a laptop and not on a phone

Figure 2 is the same page at 1280 pixels wide.

Figure 2: the same form at 1280 pixels. Nothing is wrong with it here.

Here’s the CSS that sets its widths:

/* excerpt from signup.css */
.signup-form {
  width: 600px;
  margin: 20px auto;
  padding: 20px;
  border: 1px solid var(--color-border);
}

.signup-form label {
  display: inline-block;
  width: 150px;
  text-align: right;
  margin-right: 10px;
}

.signup-form input[type="text"],
.signup-form input[type="email"],
.signup-form input[type="password"],
.signup-form select {
  width: 380px;
  padding: 5px;
  font-size: var(--step-0);
}

This snippet lists each element whose right edge is past the screen’s edge while its parent’s edge isn’t. So it finds the outermost element that’s too wide.

const edge = document.documentElement.clientWidth;
const wide = [...document.querySelectorAll("body *")].filter((el) =>
  el.getBoundingClientRect().right > edge &&
  el.parentElement.getBoundingClientRect().right <= edge);
console.log(edge, wide.map((el) => `${el.localName}.${el.className} ${Math.round(el.getBoundingClientRect().right)}`));

Pause and predict: in device mode at 390 pixels, which element does it print, and where is its right edge? Work it out from the CSS above.

Answer

In one run in Chrome 157, it printed this on signup.html:

390 ['form.signup-form 652']

The form’s content box is 600 px. The padding adds 40 px and the border 2 px, so the box is 642 px wide. It starts 10 px from the left edge of the page. 10 + 642 is 652.

On settings.html the same snippet prints table. 586, so the snapshot table is wider than a phone too.

Only the form is listed, not its fields, because the fields are inside it. One fixed width on the outside box is enough to push the whole page past the screen. So the browser makes the page 652 px wide, and the visitor has to scroll sideways.

A page must fit a screen 320 pixels wide

WCAG 2.2 makes a page that fits a narrow screen a requirement at level AA.

Reflow is content that rearranges itself to fit a narrow width, so the reader scrolls in one direction only. Success criterion 1.4.10 Reflow asks for it at a width of 320 CSS pixels for pages that scroll vertically (Understanding 1.4.10). Nothing may be lost, and nothing may need scrolling in two directions.

The number 320 comes from zoom. Suppose your window is 1280 CSS pixels wide and you zoom to 400%. Then it shows 1280 / 4 = 320 CSS pixels. The criterion helps readers with low vision who zoom in, and it arrived in WCAG 2.1, a W3C Recommendation since 5 June 2018 (What’s New in WCAG 2.1).

Some content is exempt: parts that need a two-dimensional layout, such as maps, diagrams, games and data tables. But the text around them isn’t exempt. Two failures that the Understanding document names are content that is cut off after it reflows (F102), and sticky elements that cover content at small sizes.

Two details make the 320-pixel test work on a phone:

  • The viewport tag. Every Stashling page has <meta name="viewport" content="width=device-width, initial-scale=1">. Leave out maximum-scale and user-scalable, because they block zoom (web.dev, Responsive web design basics).
  • No fixed width over 320. A box with a fixed width wider than the screen is the usual cause, as on the sign-up form. web.dev advises against fixed widths that cause sideways scrolling.

The section on breakpoints shows the form’s fix, because it needs one more idea.

Rule: Check every page at 320 CSS pixels. Only a table, a code block or a map may scroll sideways, and only inside its own box.

A layout grid: columns, gutters and margins

Look at Figure 2 again. The logo and the footer text start 10 px from the window’s left edge, and the form has edges of its own in the middle. Module 1 showed that shared edges make blocks look related.

A layout grid is a set of columns that every block on a page lines up with. A gutter is the space between two columns. A page margin is the space between the outermost column and the edge of the screen. These are the three parts that NN/g names in its article on grids (Gordon, NN/g, 2022).

Figure 3 shows the grid that Stashling uses after this module.

Figure 3: Stashling’s layout grid. At 1280 it has four card columns in a 1152 px content column; at 390, one column.

Where the 12-column grid comes from, and why it is a convention

Most grid advice you meet uses 12 columns. NN/g says a 12-column grid is generally flexible enough at desktop size, and suggests fewer columns on narrow screens. Bootstrap 5.3 has 12 columns, built with Flexbox (Bootstrap grid).

The 960 Grid System, from the years of 1024-pixel monitors, used 12 or 16 columns. Its page says 960 divides by 2, 3, 4, 5, 6, 8, 10, 12, 16, 24 and 60 (960.gs). Twelve divides by 2, 3, 4 and 6.

None of these cites a study. NN/g’s guidance rests on practice and four example sites, so this course calls the 12-column grid a convention. Josef Müller-Brockmann’s book “Grid Systems in Graphic Design” (1981) recommends a grid that fits each project and few sizes of image (excerpt). He says that fewer sizes give a quieter page.

What a grid does is limit choices. If a grid has few columns and one gutter, every block has a few places to go, so edges repeat. But if it has many thin columns, it allows so many placements that this benefit fades.

CSS Grid changes the cost. In print, a designer draws one grid for a project, and every page uses it. But in CSS, each layout can declare only the tracks it needs, such as repeat(auto-fit, minmax(12.5rem, 1fr)) for cards (web.dev, Macro layouts). Stashling uses that: one content column for every page, and card columns inside it where a page has cards.

Page margins as tokens

Pause and predict: the next change sets one rule for the header, the content and the footer. At 1280, where will the logo, the title and the footer text start?

Three tokens describe the page column:

/* excerpt from tokens.css */
  /* Layout: one content column, centered, with a margin on each side */
  --page-max: 72rem;            /* widest content column: 1152px */
  --margin-min: var(--space-4); /* page margin on a narrow screen: 16px */
  --page-margin: max(var(--margin-min), (100% - var(--page-max)) / 2);

--page-margin is the larger of two values: the minimum margin, or half of what’s left when the column is at its widest. The 100% resolves on the element that uses the token. On the header, the content and the footer, that’s the width of the page.

The header, .content and the footer each use it as side padding:

/* excerpt: the same line in three rules of base.css */
  padding: 10px var(--page-margin);
Answer

All three start 64 px from the left edge: (1280 − 1152) / 2 = 64. The gear icon ends 64 px from the right edge. On a 390-pixel phone the margin is 16 px instead of 10 px.

Figures 4 and 5 show the top of the landing page before and after.

Figure 4: before. Every block starts 10 px from the window’s edge.

Figure 5: after. The header, the content and the footer share one left edge and one right edge.

The title now wraps onto two lines. That’s because at one line it was 1172 px, wider than the new 1152 px column. Then Module 4’s text-wrap: balance splits it into two lines of similar length.

Why 72rem? It’s close to Bootstrap 5.3’s container at its xl size, 1140 px, and wide enough for four feature cards of 270 px with 24 px gutters. That’s a design choice. Because it’s in rem, it grows when a reader sets a larger default font size.

Rule: Give every page one content column with a maximum width and a minimum margin, and let the header and footer line up with it.

Content width: where the text column sits

The page column is 1152 px, but a line of text should stay near Module 4’s measure. On the landing page, the muted description is one line 1,116 px long. The article page already limits its text to 50ch (567 px at 1280), but the column sits at the left edge of the page column.

Pause and predict: on a 1280-pixel screen, where should a single column of article text sit, and why?

NN/g’s eyetracking study of 2017, with more than 120 participants on 1920 × 1080 screens, found 80% of fixations on the left half of the page (Fessenden, NN/g, 2017). Its advice is to put the primary content in the middle of the view and secondary content on the right. The article has no secondary content, so the lab centers its column.

/* excerpt from base.css */
article {
  max-inline-size: var(--measure);
  margin-inline: auto;
}
/* excerpt from index.css */
.hero .muted,
.quote {
  max-inline-size: var(--measure);
}
Answer

In the middle, with equal space on both sides. Its left edge moves from 64 px to 356 px. To us, a column at the left with the rest of the page empty looks like a page whose sidebar didn’t load. That’s our judgment, and no study tests it. On the landing page, the description and the quote wrap at 567 px.

Figure 6: before. The text column hugs the left side of the page column.

Figure 7: after. The same 567 px column, centered.

The cost is that the article’s left edge doesn’t line up with the logo anymore. But the column is the only thing on the page, so we accept that.

An article sometimes needs a picture or a table wider than its text. A full-bleed layout lets one element span the whole window, or a wider track, while the text stays in its column. Josh W. Comeau’s version is a three-column grid, 1fr min(42rem, 100%) 1fr, with every child in the middle track. A .full-bleed class spans all three (Comeau, “Full-Bleed Layout Using CSS Grid”).

He moved from ch to rem for that column, because a ch is the width of the zero in the element’s own font, not of an average letter. Module 4 used ch for the measure; both work, as long as one value sets the column. Stashling’s article has nothing to break out, so the lab keeps margin-inline: auto.

Grid or Flexbox: who decides the sizes

You know both layout methods. So the design question is which of the two should decide how wide each item is, the content or the layout.

MDN’s guide says that Flexbox starts from the content and works outward, and Grid starts from the layout and works inward (MDN, Relationship of grid layout to other layout methods). MDN adds a test. If you set widths on flex items to line them up with another row, you want Grid.

The content decides (Flexbox) The layout decides (Grid)
Nav links, button rows, tag lists Page shell, card lists that must align
Each item as wide as its text Each item as wide as its track
Wraps where it runs out of room Keeps columns when it wraps
Column sizes spread over the children Column sizes in one rule on the container

Stashling’s feature cards use Flexbox: flex: 1 1 200px on each card, with flex-wrap.

Pause and predict: at 900 pixels wide, three cards fit in the first row. What does the fourth card do?

Figure 8: Flexbox at 900 px. The fourth card stretches to 868 px.

With Flexbox, each row shares out its own space. The last row has one card, so that card takes all of it. Then its text runs in one long line, and none of its edges lines up with the cards above. The lab changes two rules:

/* excerpt from index.css */
.features {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(12.5rem, 1fr));
  gap: var(--space-5);
}

The card loses flex: 1 1 200px. 12.5rem is the old 200 px at the default font size. auto-fit drops empty tracks, so at 1280 the four cards still fill the row.

Figure 9: Grid at 900 px. The fourth card keeps its 273 px column.

The cost is the empty space to the right of the fourth card. If you want no hole, you need a number of cards that fills the rows, or a layout that lets the last card stretch. web.dev’s Macro layouts page describes the same two behaviors.

This card list is an intrinsic layout: a layout whose columns come from a minimum size and the space available, with no breakpoint. The browser adds a column whenever another 12.5rem column and its gutter fit.

Rule: Use Grid when items must share columns, and Flexbox when each item may take the size of its content.

Subgrid lines up the parts of each card

Look at Figure 9 again. The titles start at different heights, because the icons have different sizes (Module 8 fixes the icons). Each card lays out its own icon, title and text, and knows nothing about its neighbors.

Pause and predict: which CSS could make the four titles start on one line, without a fixed height?

Answer

grid-template-rows: subgrid on each card, explained below. It replaces display: flex and flex-direction: column. justify-items: start does the job of the old align-items: start, so the icons keep their width.

Subgrid, from CSS Grid Level 2, lets a grid item use its parent’s tracks instead of its own (CSS Grid 2, §9). Each card spans three rows of .features and uses those rows for its icon, title and text. Every item in a row helps size that row, so the tallest icon sets the icon row for all four cards.

/* excerpt from index.css */
/* Each card spans three rows of .features (icon, title, text), so all cards share them */
.feature {
  display: grid;
  grid-row: span 3;
  grid-template-rows: subgrid;
  justify-items: start;
  gap: var(--space-2); /* a subgrid inherits the parent's gaps unless it sets its own */
  border: 1px solid var(--color-border);
  padding: var(--space-4);
}

Figure 10: before. Titles start at 871, 895, 879 and 887 px from the top of the page.

Figure 11: after. All titles start at 895 px and all texts at 957 px.

The gap needs care. A subgrid inherits the parent’s gaps, which are 24 px here, but it can set its own (MDN, Subgrid). The card sets 8 px, so the space inside each card stays 8 px and the space between stacked cards stays 24 px. We measured both in Chrome.

Three costs come with it:

  • One long title makes every title row taller. Here that’s the point. On another page it may not be.
  • No extra rows. A subgrid has no implicit tracks in the subgridded direction. A fourth child in a card that spans three rows piles into the last row.
  • The structure is fixed. Every card must have the same parts in the same order.

Subgrid has been Baseline widely available since 2026-03-15: Firefox 71 in 2019, Safari 16 in 2022, and Chrome 117 in September 2023 (web-features 3.46.0). Before subgrid, the options were display: contents on the card, which removes the card’s box and border, or fixed heights, which break with longer text.

Breakpoints chosen by the content

Now back to the form. It needs a layout that changes with the width: labels above fields when the form is narrow, labels beside fields when there’s room.

Ethan Marcotte described responsive design in 2010, with three parts: fluid grids, flexible images and media queries (Marcotte, A List Apart, 2010). A breakpoint is a width at which the layout changes.

A common habit is a fixed list of breakpoints, such as Bootstrap 5.3’s 576, 768, 992, 1200 and 1400 px. But web.dev advises the other way: start with the narrow layout, widen the window until the content looks wrong, and put a breakpoint there (web.dev, Responsive web design basics). Android’s window size classes are based on device share, and even Android’s page says not to use them to detect a tablet (Android, Window size classes).

So the form’s breakpoint comes from the form. Labels beside fields need a label column, a gap and a field wide enough for an email address. We widened the form in device mode and typed dana.okafor@example.com into the Email field. At a form width of 22rem, 352 px, a 6em label column and a 12 px gap leave a field that holds the address with room to spare.

Write breakpoints in em or rem

Pause and predict: a reader sets the browser’s default font size to 24 px. A breakpoint written as @media (width >= 40em): at what window width does it apply now?

Answer

At 960 px instead of 640 px. Media Queries Level 4 says relative units in a media query use the initial value (Media Queries 4). So em and rem there follow the reader’s default font size, whatever the page’s CSS sets. A breakpoint in px wouldn’t move.

That’s the behavior you want, because a reader with larger text gets the narrow layout sooner, at the width where the text needs it.

A container query lets the form ask for its own width

A media query asks about the window. But the form is a component: on this page it sits in a centered column, and a later page might put it in a sidebar. web.dev’s Micro layouts page makes this point: a component has no awareness of its context, so media queries suit page layout and container queries suit components (web.dev, Micro layouts).

A container query styles elements by the size of an ancestor that you mark as a container. You mark it with container-type: inline-size. That turns on size containment in the inline direction: the browser sizes the container without looking at its children. Otherwise a query could change the content, the content could change the size, and the size could change the query again (MDN, container-type).

Here’s the new signup.css, in full:

.signup-form {
  container-type: inline-size; /* the rules in @container below ask this form for its width */
  max-inline-size: var(--measure);
  margin: 20px auto;
  padding: 20px;
  border: 1px solid var(--color-border);
}

/* Narrow form: each label above its field */
.signup-form .row {
  display: grid;
  gap: var(--space-1);
  margin-bottom: 10px;
}

.signup-form input[type="text"],
.signup-form input[type="email"],
.signup-form input[type="password"],
.signup-form select {
  padding: 5px;
  font-size: var(--step-0);
}

.signup-form .checkbox-row {
  display: flex;
  align-items: baseline;
  gap: var(--space-2);
}

.signup-form .actions {
  text-align: right;
}

/* Wide form: room for a 6em label column and an email address beside it */
@container (width >= 22rem) {
  .signup-form .row:not(.checkbox-row) {
    grid-template-columns: 6em 1fr;
    align-items: baseline;
    column-gap: var(--space-3);
  }

  .signup-form .row label {
    text-align: right;
  }
}

Notice four things:

  1. No fixed width is left. The form is at most var(--measure) wide, and the fields fill their grid cells.
  2. The narrow layout is the default, and the query adds the wide one. A browser that ignores the query still shows a working form.
  3. The checkbox row is Flexbox and the other rows are Grid. The checkbox and its label take their own sizes; the label column must be the same in every row.
  4. The query uses rem. In this query, rem follows the reader’s default font size, as em does in a media query.

Figures 12 and 13 show the result at both widths.

Figure 12: after, at 390 px, in the same crop as Figure 1. Each label sits above its field, and the button is on screen.

Figure 13: after, at 1280 px, in the same crop as Figure 2. The form keeps labels beside fields, because it’s wider than 22rem.

Labels above fields on a phone also match NN/g’s advice for mobile forms (Whitenton, NN/g, 2016). The form stays one field per row at every width.

NN/g reports a CHI 2014 study by Seckler and colleagues, in which forms that followed its guidelines were completed faster. With them, 78% against 42% of forms were sent without an error on the first try. We didn’t open the paper itself.

Baymard’s checkout testing found that forms with several fields per row caused skipped and misread fields. Its one exception is two or three fields that belong to one entity, such as first and last name or the parts of a date (Scott, Baymard, 2023). Whether labels belong beside or above fields on a wide screen is a question for Module 10, Forms, Tables and the Words in Them.

What the rem breakpoint does with a larger default font

We ran the form in headless Chrome 157 and set the default font size through the DevTools protocol (Page.setFontSizes). The numbers are from one run.

Default font size Breakpoint Window width where labels move beside fields Email field’s inner width Width of dana.okafor@example.com
16 px 22rem 426 px 229 px 210 px
24 px 22rem 618 px 350 px 314 px
24 px 352px 442 px 272 px 310 px

With a px breakpoint and 24 px text, the form puts the label beside a field that’s too narrow for the address. But with rem, the breakpoint moves with the text, so the address fits.

Container size queries have been Baseline widely available since 2025-08-14 (Chrome 105, Firefox 110, Safari 16). Container queries can also ask about other things: style queries on custom properties are newly available since 2026-05-19, and queries by container name alone since 2026-05-07 (web-features 3.46.0). Scroll-state queries work in Chrome and Edge only.

Rule: Find each breakpoint by widening the content until it breaks, write it in rem or em, and use a container query when the component’s own width decides.

Reading order follows the HTML, not the picture

The layout tools so far move boxes on screen, but they don’t move them in the HTML. That gap matters to everyone who doesn’t read the page by looking at it.

Reading order is the order in which a screen reader reads the content and the Tab key moves through it. It’s the order of the HTML, the DOM order. WCAG 2.2 has two criteria for it at level A. 1.3.2 Meaningful Sequence asks that the correct order can be determined by software when order changes meaning (Understanding 1.3.2). 2.4.3 Focus Order asks that focus moves in an order that keeps meaning and operability (Understanding 2.4.3).

Pause and predict: on the settings page, someone moves the Danger zone section to the top with order: -1 on a flex column. A keyboard user opens the page and presses Tab. Where does focus go first, and where is the Delete repository button in the Tab order?

Answer

Focus goes first to the links in the header, then to the Name field, as before. The Delete repository button is still last, after the snapshot table, although it’s now drawn at the top. CSS Grid Level 1 says order and grid placement don’t change speech order or the order of sequential focus (CSS Grid 1, Reordering and Accessibility). So a sighted keyboard user sees focus jump from the bottom of the page to the top.

The specification goes further. It says authors must use order and grid placement “only for visual, not logical, reordering of content”. MDN names grid-auto-flow: dense as a common way to break the order by accident, because it fills holes with later items (MDN, Grid layout and accessibility). To fix it, change the HTML, and to check it, put the mouse away and press Tab through the page.

Everything in this module keeps the DOM order. The cards, the form rows and the page column only change sizes and wrap; nothing moves before something that comes earlier in the HTML.

The table: one focusable box that scrolls

On the settings page, the snapshot table makes the whole page 586 px wide on a 390-pixel phone. The table needs its columns, so 1.4.10 lets it keep them. But the text around it must still fit.

Pause and predict: you wrap the table in a box with overflow-x: auto. A keyboard user wants to read the Status column. How do they scroll the box?

The lab wraps the table in a box that scrolls and can take focus. The pattern is Adrian Roselli’s (Roselli, “Under-Engineered Responsive Tables”):

<!-- excerpt from settings.html -->
<h2 id="snapshots-title">Snapshots</h2>
<p>Select a snapshot to restore its files.</p>
<div class="table-scroll" role="region" aria-labelledby="snapshots-title" tabindex="0">
<table>
  …
</table>
</div>
/* excerpt from settings.css */
/* The table keeps its columns and scrolls inside this box; the page does not scroll sideways */
.table-scroll {
  max-inline-size: 100%;
  overflow-x: auto;
}
Answer

They press Tab until the box has focus, then use the arrow keys. tabindex="0" puts the box in the Tab order, after the field before it in the HTML, and aria-labelledby gives it the name “Snapshots”. Chrome has made scroll boxes focusable by default since version 132, but only when they hold nothing focusable (Chrome for Developers). This table holds checkboxes, so the attribute is needed.

Figure 14: before, at 390 px. To see the Status column, the reader scrolls the whole page, and the text slides off screen.

Figure 15: after, at 390 px. Only the table scrolls, inside its box; the heading and text stay in place.

Roselli’s October 2026 update reports that the W3C’s accessibility guidelines group decided a focusable element that isn’t interactive needs no role, so tabindex="0" alone may be enough. We didn’t check that decision at the W3C, so the lab keeps the role and the name.

reading-flow, and what it is for

CSS Display Level 4 has a newer answer: reading-flow on a flex or grid container makes speech and focus follow the visual order, for example reading-flow: grid-rows (CSS Display 4). Chrome shipped it in version 137 in 2025 (Chrome for Developers). It has limited availability: Chrome and Edge only, with no Firefox or Safari (web-features 3.46.0).

But its own specification says the source document should still express the logical order. reading-flow is meant for a layout with more than one correct order at different widths; HTML in the wrong order stays wrong. Without support, focus and screen readers follow the DOM, so write the DOM in the right order first.

Rule: Put content in the HTML in the order people should read it, and use layout only to place it.

Where people look, and what the evidence says

Layout advice often comes with a reading pattern: “people read in an F”, “design in a Z”. Some of this has evidence, and some doesn’t.

The F-pattern is a way of scanning text in two horizontal sweeps and one vertical one down the left side. Jakob Nielsen reported it in 2006 from eyetracking with 232 users (Nielsen, NN/g, 2006). The F is a rough shape; NN/g says it can look like an E or an inverted L.

A 2017 re-study corrected a common reading of that finding (Pernice, NN/g, 2017). The F appears when text has little formatting, the reader wants to be quick, and isn’t committed to reading it all. It holds on phones too, mirrored in right-to-left languages. NN/g calls it a bad outcome that makes readers miss content, and says a design shouldn’t aim for it.

The layer-cake pattern is a way of scanning in which the eyes jump from heading to heading and read a section only when its heading fits the task. NN/g’s 2019 article calls it the most effective of the scanning patterns it describes, and lists it with the F, spotted and commitment patterns (Pernice, NN/g, 2019). Its evidence is heatmaps and single gaze plots, with no method or participant count given, so treat it as an observation without a measured size of effect.

The Z-pattern is a claimed eye path along the top of a page, diagonally down, then along the bottom to a call to action at the bottom right. Brandon Jones popularized it in 2010 as a design approach for simple pages (Jones, Envato Tuts+, 2010). The article cites no study, rests on left-to-right reading, and says it isn’t universal. We found no NN/g eyetracking study of a Z-pattern, so the Z is a convention.

What the evidence supports is plainer. NN/g’s 2018 scrolling study found 57% of viewing time above the fold and 74% in the first two screenfuls (Fessenden, NN/g, 2018). Its advice is to put key content and the main call to action high.

In 2017, NN/g compared zigzag rows of image and text with aligned rows on four live sites, about 30 to 35 participants per version. Decorative images in zigzag rows drew brief, wasted fixations, while readers of aligned rows mostly skipped them (Flaherty, NN/g, 2017). NN/g calls zigzag acceptable for two or three rows.

For Stashling, this means three things. The Download button stays in the first screen. The article keeps headings that start with the words that carry information, such as “Why fixed-size chunks were not enough”, so layer-cake scanning works. And the feature cards stay in aligned rows.

Choices and costs

Decision Choice in the lab Cost or limit Choose something else when
Page column Padding from --page-margin, 72rem at most One more token; text still needs its own measure Elements must break out of the column: a full-bleed grid, 1fr min(42rem, 100%) 1fr
Grid system Only the tracks each layout needs No shared column lines between page types Many templates share edges, or a designer hands you a 12-column grid
Article column Centered Its edge no longer lines up with the logo A sidebar fills the right side: keep the column on the page’s left edge
Card list Grid, auto-fit and minmax() A hole in the last row (Figure 9) Items differ in size and may stretch, such as tags or buttons: Flexbox with flex-wrap
Card parts Subgrid One long title makes every title row taller; fixed structure Cards differ in parts: let each card lay itself out
Form layout Container query Size containment: on an element that shrinks to fit its content, the container can collapse The page shell changes: a media query
Breakpoint value Found by widening the content, in rem Each component gets its own numbers The layout only needs to wrap: an intrinsic layout needs none
Wide table A focusable box that scrolls Columns past the edge are hidden until the reader scrolls The table can lose columns or stack its rows: Module 10
Order HTML order = visual order The HTML must change when a layout needs a new order Several correct orders per width: reading-flow, Chrome only

What changed recently in CSS and standards

All Baseline statuses are from the web-features data (version 3.46.0), read on 2026-11-18.

  • Subgrid became Baseline widely available on 2026-03-15. Chrome 117 made it newly available on 2023-09-15.
  • Container size queries became widely available on 2025-08-14. Style queries on custom properties became newly available on 2026-05-19, when Firefox 151 added them; Firefox’s release notes say it also accepts standard properties. Queries by container name alone became newly available on 2026-05-07.
  • The range syntax for media queries, (width >= 40em), became widely available on 2025-09-27. The course uses the same syntax in container queries.
  • reading-flow and reading-order shipped in Chrome 137 in 2025 and are still limited to Chromium browsers.
  • display: grid-lanes, the masonry layout, is limited: the data lists Safari 27.2 only.
  • WCAG 2.2, with 1.4.10 Reflow from WCAG 2.1, is a W3C Recommendation in its 12 December 2024 edition.

Grid, Flexbox, gap in Flexbox, min(), max(), clamp() and the logical properties such as max-inline-size and padding-inline are all widely available.

Online tools for this step

All three were checked on 2026-11-18. None replaces testing the page at 320 pixels and with the Tab key.

  • Chrome DevTools device mode. It sets a viewport size, with presets from Mobile S at 320 px to 4K at 2560 px. A bar lists the page’s media query breakpoints; click one to jump to it. It can also throttle the CPU and network and take screenshots. Limit: its documentation calls it a first-order approximation and points to remote debugging on a real device for accuracy. It’s built into Chrome.
  • Chrome DevTools grid inspector and Firefox’s Grid Inspector. Both mark each grid and subgrid, draw overlays with line numbers and track sizes, and can extend the lines across the page. Firefox shows each subgrid indented under its parent, with the parent’s lines. Limit: each works in its own browser only. Use either to check that the card rows in Figure 11 come from .features.
  • Responsively App. A desktop browser that you install, which shows one page at many device sizes at once and mirrors clicks and scrolling across them. It has more than 30 device profiles and takes screenshots. Limit: you must download and install it, and it’s AGPL-3.0 licensed. DevTools overlap: device mode shows one size at a time, and this shows many.

Check yourself

Critique: the landing page that follows a Z

A team redesigns a product’s landing page. Each feature is a row with a decorative photo on one side and text on the other, and the side swaps on every row: six rows in all. The team puts the main “Start free” button at the bottom right of the first screen, below a large photo, “because readers follow a Z”. The sign-up form further down has First name and Last name on one row, and Email and Password side by side on the next row.

Test users say the page is “busy”, and many skip the Password field.

Hint 1

What did NN/g’s zigzag study find for decorative images, and how many rows did it call acceptable?

Hint 2

Is the Z-pattern a finding or a convention? Where does the scrolling study say the main call to action belongs?

Hint 3

Which pairs of fields does Baymard allow on one row?

Answer

Three problems, each with evidence behind the fix.

  1. The six zigzag rows with decorative photos make readers spend fixations on images that tell them nothing. NN/g found that aligned rows let readers skip such images, and called zigzag acceptable for two or three rows. So align the rows: images in one column, text in the other, or drop the decorative images.
  2. The Z-pattern is a convention with no eyetracking study behind it. But the scrolling study supports putting the main action high on the page. So move “Start free” up, near the headline, and keep it in the first screen at 390 px too.
  3. First name and Last name may share a row, because they’re parts of one entity, Baymard’s exception. But Email and Password are two separate answers, and fields side by side are the ones testers skip. So put them on their own rows, one field per row.

Review questions

  1. A page passes at 390 px but scrolls sideways at 320. Does it meet 1.4.10, and which content may still scroll sideways?
  2. What are the three parts of a layout grid, and why does this course call the 12-column grid a convention?
  3. Four cards wrap onto two rows. Which layout method keeps the last card the width of the cards above it, and why? And what makes the titles of all cards start on one line?
  4. Why does the form’s breakpoint use a container query and rem, and not a media query in px?
  5. A designer moves the newsletter box above the article with order: -1. What does a keyboard user notice, and what is the fix? And which scanning pattern does NN/g call a bad outcome?
Answers
  1. No. 1.4.10 asks for reflow at 320 CSS px, which is 1280 px at 400% zoom. Only content that needs two dimensions, such as a data table, a map or a diagram, may scroll sideways, and the text around it must still fit.
  2. Columns, gutters and page margins. Twelve divides by 2, 3, 4 and 6 and comes from practice such as 960.gs and Bootstrap; NN/g cites no study for it.
  3. Grid. The column sizes are set on the container, so the last row uses the same tracks. In Flexbox each row shares out its own space, and a lone card takes all of it. For the titles, each card spans three rows of the list and uses them with grid-template-rows: subgrid.
  4. The form is a component, so its own width decides, wherever it sits. In rem the breakpoint moves with the reader’s default font size; in px a reader with 24 px text gets a field too narrow for an email address.
  5. Focus still reaches the newsletter box in its HTML position, after the article, so focus seems to jump. Change the HTML order instead. The F-pattern.

The lab: margins, a content column, grids and a form that fits

In about 15 minutes, you make the sign-up form fit a phone, give every page one set of margins and center the article. Then you put the feature cards on a grid with subgrid, and let the snapshot table scroll in its own box. Start from the module-06 folder, keep DevTools in device mode, and reload after each step. The finished files are in the module-07 folder of the course repository.

Step 1: make the sign-up form fit

Why: fixed widths push the page past the screen, and the form should change its layout by its own width (see “Breakpoints chosen by the content”).

Run the console snippet from the first section on signup.html at 390 px. Then replace all of signup.css with the file in “A container query lets the form ask for its own width”.

What you should see: Figure 12 at 390 px and Figure 13 at 1280 px. The snippet prints 390 []. Drag the device-mode width up from 390: at 414 px, the labels move beside the fields. After step 2 adds wider margins, that happens at 426 px.

Step 2: set the page margins

Why: the header, content and footer should share one left and one right edge (see “A layout grid: columns, gutters and margins”).

In tokens.css, add an empty line after the --tracking-tight line, then these lines:

  /* Layout: one content column, centered, with a margin on each side */
  --page-max: 72rem;            /* widest content column: 1152px */
  --margin-min: var(--space-4); /* page margin on a narrow screen: 16px */
  --page-margin: max(var(--margin-min), (100% - var(--page-max)) / 2);

In base.css, the rules .site-header, .content and .site-footer each have padding: 10px;. Change that line in all three to this:

  padding: 10px var(--page-margin);

What you should see: Figure 5 beside Figure 4 at 1280 px. At 390 px, every page has 16 px on each side instead of 10 px.

Step 3: place the text columns

Why: text keeps its measure inside the wider page column, and the article sits in the middle (see “Content width: where the text column sits”).

In base.css, add one line to the article rule:

article {
  max-inline-size: var(--measure);
  margin-inline: auto;
}

In index.css, add this rule after the .muted rule:

.hero .muted,
.quote {
  max-inline-size: var(--measure);
}

What you should see: Figure 7 beside Figure 6 on article.html at 1280 px. On the landing page, the description and the quote wrap at 567 px.

Step 4: put the feature cards on a grid

Why: the cards should share columns when they wrap (see “Grid or Flexbox: who decides the sizes”).

In index.css, replace the .features rule with this one, and delete the line flex: 1 1 200px; from .feature:

.features {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(12.5rem, 1fr));
  gap: var(--space-5);
}

What you should see: set the device-mode width to 900. Figure 9 instead of Figure 8: the fourth card keeps its column. At 1280 px the four cards still share one row, each 270 px wide.

Step 5: line up the card parts with subgrid

Why: the titles and texts of all cards should start on the same lines (see “Subgrid lines up the parts of each card”).

In index.css, replace the .feature rule with this one:

/* Each card spans three rows of .features (icon, title, text), so all cards share them */
.feature {
  display: grid;
  grid-row: span 3;
  grid-template-rows: subgrid;
  justify-items: start;
  gap: var(--space-2); /* a subgrid inherits the parent's gaps unless it sets its own */
  border: 1px solid var(--color-border);
  padding: var(--space-4);
}

What you should see: Figure 11 instead of Figure 10 at 1280 px. In the Elements panel, .features has a grid badge and each card a subgrid badge; click one to see the shared rows.

Step 6: let the table scroll in its own box

Why: the table may keep its columns, but the page may not scroll sideways (see “The table: one focusable box that scrolls”).

In settings.html, give the Snapshots heading an id, and wrap the table, from <table> to </table>, in a div:

<!-- excerpt from settings.html -->
<h2 id="snapshots-title">Snapshots</h2>
<p>Select a snapshot to restore its files.</p>
<div class="table-scroll" role="region" aria-labelledby="snapshots-title" tabindex="0">
<table>
  …
</table>
</div>

In settings.css, add max-inline-size: 100%; to the .settings .field rule. Then replace the .settings input, .settings select rule, and add the .table-scroll rule after it:

.settings .field {
  gap: var(--space-1);
  max-inline-size: 100%;
}

.settings input,
.settings select {
  font-size: var(--step-0);
  box-sizing: border-box; /* so 100% includes padding and border */
  max-inline-size: 100%;
}

/* The table keeps its columns and scrolls inside this box; the page does not scroll sideways */
.table-scroll {
  max-inline-size: 100%;
  overflow-x: auto;
}

The .field and input lines are for the Repository field. Its size="40" makes it 375 px wide, so without them it would push the page past a 320-pixel screen.

What you should see: Figure 15 instead of Figure 14 at 390 px, after you scroll the table to its end.

Step 7: check at 320 pixels and with the Tab key

Why: every page must reflow at 320 px and keep its order (see “A page must fit a screen 320 pixels wide”).

Set the device-mode width to 320. On each of the four pages, run this in the console:

document.documentElement.scrollWidth

Then open settings.html, put the mouse away, and press Tab from the top of the page. When the table box has focus, press the right arrow key.

What you should see: 320 on all four pages; before the lab, signup.html printed 652 and settings.html 583.

The first section’s snippet still lists the table on the settings page, because the table’s box reaches past the screen inside its scroll box; the page itself doesn’t scroll. The code blocks on the landing and article pages also scroll inside their own boxes, because a line of code can’t wrap without changing what it shows. Tab moves from the header links through the fields and buttons, then to the table box, which shows the browser’s default focus ring, then to the checkboxes in the table. The right arrow key scrolls the table.

Optional: apply it to a page of your own

Pick a page of your own with a form, a table or a list of cards.

  1. Run the first section’s snippet at 320 px, and replace each fixed width it finds with a maximum width.
  2. Add page-margin tokens and use them on the header, the content and the footer, so all three share two edges.
  3. Make each list of cards a grid with auto-fit and minmax(). If the cards have parts that should line up, give each card a subgrid.
  4. For each component that changes layout, widen it until it looks wrong, and write that width in rem in a container query.

Then press Tab through the page and compare the focus order with what you see.

Module 7 cheat sheet

Reflow     every page works at 320 CSS px; only tables, code, maps scroll
Grid       columns + gutters + page margins; 12 columns is a convention
Margins    --page-margin: max(16px token, (100% - --page-max) / 2)
Text       text keeps --measure inside the page column; center one column
Who sizes  content decides: Flexbox; layout decides: Grid with auto-fit
Subgrid    card spans N rows, grid-template-rows: subgrid, own gap
Breakpoint widen until the content breaks; write it in rem or em
Container  container-type: inline-size; @container (width >= 22rem)
Order      HTML order = reading order; layout never reorders meaning

Module 8, Images and Icons, starts with the landing page’s stretched photo and its mixed icons.

Sources

Standards:

Layout and responsive design:

Grids, cited for what they recommend:

Reading and forms research:

Browsers:

  • The web-features data, version 3.46.0, for every Baseline status in this module.

The measured numbers in this module, such as edges, widths and breakpoint widths, come from runs of the lab pages in headless Chrome 157 on macOS. The default font size was 16 px unless the text says otherwise. Your numbers will differ with other fonts, browsers and settings.