Web Design for Developers / Module 09

Module 9: Components, States and Motion

Make a disabled button look disabled and links look like links, then give every component a focus ring, a target size, depth and small motion.

This is the bottom of Stashling’s settings page, as Module 8 left it, 1280 pixels wide in the light theme.

Figure 1: the settings page at 1280 pixels. “Restore selected” is disabled, but it looks like every other button.

And this is a paragraph from the blog article on the same site.

Figure 2: a paragraph of the article. The words “settings page” are a link.

A reader would say the page lies about what works. The blue button can’t be pressed, and nothing tells you why. The link looks like the words around it, so you’ll find it only if your pointer happens to pass over it.

This module is about components: the buttons, links and menus a reader acts on. It covers how a reader sees what can be clicked, and the states each component goes through. Then it takes up keyboard focus, target size, depth, corners and small motion. Each part ends as CSS in the sample site.

After this module, you can:

  • give links and buttons visible cues, and check a link’s color against the text around it as well as the background
  • style every state of a button, including a disabled state that looks disabled and a hover that only appears where a pointer can hover
  • draw a focus ring and show, with computed ratios, that it reaches 3:1 on every background it can sit on in both themes
  • size click and tap areas to WCAG 2.5.8, and say when to go to 44 pixels
  • add depth, corners and motion from shared tokens, with a reduced-motion version and durations stated as conventions

To follow along, start from the module-08 folder of the course repository, github.com/vespaiach/web-design-course. Open settings.html and article.html in Chrome at 1280 pixels wide.

Two controls that do not look like controls

Pause and predict: in Figure 1, which button can you press? In Figure 2, which words are a link? Then look at base.css in module-08 and find the rules that cause both.

Answer

From the picture alone, you can’t tell. “Restore selected” has the disabled attribute in settings.html, so a click does nothing. But .button sets the fill, the text color and cursor: pointer for every button, disabled or not, and no rule changes them for :disabled.

The link is “settings page”. The rule a { color: inherit; text-decoration: none; } was written for the header’s nav, but it applies to every link on the site. Only a:hover brings the underline back, so a link shows itself after the pointer is already on it.

Both problems come from CSS that was right for one place and then applied everywhere. So a fix needs a reason for each choice, and that reason starts with how a reader decides what can be clicked.

How a reader sees what can be clicked

Don Norman brought a word from perception research to design in 1988. An affordance is an action that an object makes possible for a person, such as a handle that can be pulled. Norman later wrote that the word was “widely used and misused”, because on a screen nearly everything can be clicked (Norman, 2008).

So he added a second word. A signifier is any cue a person can perceive that shows where and how to act, such as an underline, a button’s filled shape or a scrollbar. On a page, the affordance is rarely the problem. The signifier is.

Flat design is a style that removes depth cues such as shadows, gradients and bevels, so controls are flat areas of color or plain text. NN/g tested what that costs (Moran, NN/g, 2017). 71 users looked at nine web pages, each built twice: once with strong signifiers and once with weak ones. Their task was to find a link, tab, button or slider.

With weak signifiers, users took 22% more time and looked at 25% more places before they found the target. On one pair, 86% of users found a link right after reading the heading on the strong version, against 50% on the weak one.

The study has limits, which the article states. The tasks were short, on one page, and did not test whether people discover controls they weren’t looking for. Weak signifiers still worked on simple pages with plenty of space, a familiar layout and high contrast.

NN/g’s guidance on clickable elements adds three points, from expert review rather than a test (Loranger, NN/g, 2015):

  • Blue, underlined text is the safest link style.
  • A button should look like a button: a rectangle, with rounded corners if you like. A three-dimensional look is one of the strongest cues.
  • Never give text that does nothing the link color or a button’s background.

Rule: Give every control a signifier that shows before the pointer reaches it, and give nothing else that signifier.

Links that look like links

Stashling’s links have no signifier at all. The fix needs a color and an underline, and the reason for both is a WCAG rule that’s easy to miss.

WCAG 2.2 success criterion 1.4.1, Use of Color, says that color must not be the only way to show information (Understanding 1.4.1). So a link that differs from the text around it only by hue fails, as failure F73 describes. A link exactly like body text doesn’t fail 1.4.1, because no color carries the meaning, but readers can’t find it.

Technique G183 allows color alone in one case (G183). The link must have 3:1 contrast against the text around it, and both must still have 4.5:1 against the background. G183 calls that combination challenging and suggests an underline instead.

Pause and predict: the lab’s link token will be the accent blue, #0078cd in the light theme and #77c4ff in the dark theme. Does color alone pass G183 in each theme?

Answer

In the light theme, yes. #0078cd is 4.60:1 on white and 3.46:1 against the body text #222222. In the dark theme, no. #77c4ff is 8.43:1 on #222222, but only 1.54:1 against the body text #e8e8e8. Both numbers come from the script below.

The script is the WCAG 2 contrast function from Module 6, run on the site’s tokens:

// contrast.mjs: run with `node contrast.mjs`. The same functions are in color-calc/m9/m9.mjs.
const hex2rgb = h => [1, 3, 5].map(i => parseInt(h.slice(i, i + 2), 16));
const lin = c => (c <= 0.04045 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4);
const lum = h => { const [r, g, b] = hex2rgb(h).map(v => lin(v / 255)); return 0.2126 * r + 0.7152 * g + 0.0722 * b; };
const ratio = (a, b) => { const [hi, lo] = [lum(a), lum(b)].sort((p, q) => q - p); return (hi + 0.05) / (lo + 0.05); };

console.log(ratio("#0078cd", "#ffffff").toFixed(2), ratio("#0078cd", "#222222").toFixed(2)); // 4.60 3.46
console.log(ratio("#77c4ff", "#222222").toFixed(2), ratio("#77c4ff", "#e8e8e8").toFixed(2)); // 8.43 1.54

There’s a reason the dark theme fails, and it goes deeper than these two colors. When the link’s luminance lies between the background’s and the text’s, the two ratios multiply to the ratio of text on background. In the light theme, 4.60 × 3.46 = 15.91, which is exactly #222222 on white.

So G183 needs text-on-background contrast of at least 4.5 × 3 = 13.5:1. The light theme has 15.91:1, so a link color can meet both. But the dark theme’s text is 12.98:1 on its surface, so no link color can, whichever you choose.

An underline doesn’t depend on any of these numbers, so the lab keeps the browser’s underline on every link and moves the line a little lower:

/* excerpt from base.css */
a {
  color: var(--color-link);
  text-underline-offset: 0.2em; /* clear of the letters, so g and y stay readable */
}

a:hover {
  text-decoration-thickness: 2px;
}

text-underline-offset moves the line away from the letters, so it doesn’t cut through the bottoms of g, j and y. It’s Baseline widely available since 2023-05-19. text-decoration-thickness is widely available too; MDN says it has worked across browsers since March 2021. On hover the line gets thicker, which confirms the link without changing its color.

But the header’s nav needs the opposite. Its links sit on the dark bar, where the blue would be 3.46:1 at best, and a row of links in a header already reads as navigation. So the old rule moves from every link to the header only:

/* excerpt from base.css */
/* The nav and the logo keep the bar's colors; their place in the header says they are links */
.site-header a {
  color: inherit;
  text-decoration: none;
}

.site-header a:hover {
  text-decoration: underline;
}

Figure 3 shows the same paragraph after the change.

Figure 3: after. A link color and an underline. In the light theme, the color alone would pass G183; the underline makes the dark theme pass too.

The cost is visual noise in text with many links, such as a reference page. Some sites underline only links inside paragraphs and rely on position for lists of links, as the header does here. That’s a judgment about layout, not a WCAG exception.

Rule: Underline links in text. If you rely on color alone, check the link against the text around it (3:1) and against the background (4.5:1), in every theme.

A component and its states

A component is a reusable piece of interface with one job and one look everywhere it appears, such as a button, a link or a menu. A state is one of the conditions a component can be in, each with its own look, such as hovered or disabled.

NN/g lists the states a button goes through (Gordon, NN/g, 2025):

State What it tells the reader CSS
Enabled You can use this the base rule
Hover The pointer is on it :hover
Focus The keyboard is on it :focus-visible
Pressed Your click is happening :active
Disabled You cannot use it now :disabled
Loading Your action is running a label and an attribute, set by a script

“Selected” belongs to checkboxes and tabs, not buttons. NN/g also suggests timings for state changes, which the motion section returns to. Those numbers are practice, not a study.

Figure 4 shows one Stashling button in five states, before and after this module’s lab. The states are forced with DevTools’ state controls, so each copy shows one state.

Figure 4: one button in five states, before and after the lab. Before, disabled looks enabled and focus is hard to see.

Hover exists only where a pointer does

A touch screen has no pointer resting on anything. But browsers on phones still apply :hover after a tap and keep it until you tap elsewhere, so a button can look stuck in its hover color.

The media feature hover tests whether the main input can hover (Media Queries 4, interaction). It’s Baseline widely available since 2021-06-11:

/* excerpt from base.css */
/* Only where a pointer can hover: on a touch screen, :hover sticks after a tap */
@media (hover: hover) {
  .button:hover:not(:disabled) {
    background: color-mix(in oklab, var(--fill), black 15%);
  }
}

A hover state isn’t required for contrast. WCAG’s 1.4.11 calls hover supplemental, because the pointer itself already shows where you are (Understanding 1.4.11). But a hover must not lower contrast below the minimum, and Module 6 checked that: 6.60:1 in the light theme and 5.46:1 in the dark one.

Pressed: move, do not darken further

The first idea for a pressed state is a darker fill than hover. But in the dark theme that fails, because the button’s text is dark.

Pause and predict: the dark theme’s button is #222222 text on #77c4ff. The hover mixes in 15% black and gives 5.46:1. What does 25% black give?

Answer

#4f85ae, with 4.01:1 for the text, below the 4.5:1 that WCAG 1.4.3 asks for. Each step toward black moves the fill toward the dark text. But in the light theme the text is white, so it gains contrast as the fill darkens (8.33:1 at 25%).

So the lab’s pressed state changes position, not color:

/* excerpt from base.css */
/* Pressed: the button moves down 1px, like a key */
.button:active:not(:disabled) {
  transform: translateY(1px);
}

The move is small, and it isn’t animated, so it isn’t motion in the sense of the last section. The cost is that it’s easy to miss. That’s acceptable for pressed, which lasts a fraction of a second while the pointer already sits on the button.

Loading: say what is happening

A loading state appears when an action takes longer than the reader expects. Nielsen gives three limits from Usability Engineering (1993), built on research from 1968 and 1991 (Nielsen, NN/g). 0.1 s feels instant, 1 s keeps the reader’s flow, and 10 s is about where attention leaves.

These are long-standing rules of thumb, not recent experiments. Their use here is simple. Under about one second, show nothing. Above it, change the label. Above about ten seconds, show progress, such as “Restoring 3 of 8 files”.

A loading button keeps its place and its width, and says what it does:

<!-- excerpt: a loading state, not part of the lab -->
<button class="button" type="submit" aria-disabled="true">Saving…</button>

The lab has no server, so it has no loading state. The next section explains aria-disabled.

Rule: Give every component a look for each of its states, and check each look’s contrast in both themes.

A disabled button that looks disabled

The fix for Figure 1 starts with a question: should the button be disabled at all? The sources disagree.

GOV.UK’s design system asks teams to avoid disabled buttons, because they “have poor contrast and can confuse some users” (GOV.UK Design System, Button). Vitaly Friedman and Adam Silver list the same problems (Friedman, 2021; Silver, 2023). A disabled button gives no reason, takes no keyboard focus, and is hard to read. Readers may also miss the moment it becomes enabled.

Their alternative is an enabled button that explains the problem when someone presses it. But NN/g accepts disabled buttons that stay readable, with aria-disabled so that they keep focus (Gordon, 2025). All of these are expert opinions, not studies.

Two uses are worth separating. Disabling a submit button after the first click, so an order isn’t sent twice, has support from a study of form guidelines (Seckler and others, CHI 2014). Disabling a button until a form is valid is the case the critics mean.

Stashling’s button is the second kind: it waits for a selected snapshot. The lab keeps it disabled, because making it enabled needs a script that the site doesn’t have yet. It changes two things: the look and an explanation.

WCAG exempts disabled controls from its contrast rules (Understanding 1.4.11). So the low contrast many sites use is legal, and it’s also why people can’t read them. The lab keeps the text readable and removes the accent fill, which is what says “this works”:

/* excerpt from base.css */
/* Disabled: no accent fill, so it no longer looks like the buttons that work */
.button:disabled {
  --fill: var(--color-surface-alt);
  color: var(--color-muted);
  cursor: not-allowed;
}

The text is 5.37:1 in the light theme (#5d5d5d on #e8e8e8) and 5.07:1 in the dark theme (#a4a4a4 on #333333). cursor: not-allowed is a convention, and it does nothing on touch screens.

The reason moves next to the button, and the button points to it:

<!-- excerpt from settings.html -->
      <p id="restore-hint">Select a snapshot to restore its files.</p>
      <button class="button" type="button" disabled aria-describedby="restore-hint">Restore selected</button>

The sentence was already on the page, above the table. But next to the button, it answers “why can’t I press this?” where the question comes up.

Pause and predict: what changes in Figure 1 after these two edits? Look at the button, the sentence and the red button below.

Figure 5: after. The disabled button loses the accent fill, and its reason sits right above it.

Answer

The disabled button turns light gray with gray text, and the sentence sits right above it. The red button doesn’t change: its .button-danger fill still applies, because it isn’t disabled. The table moved up by one line, because the sentence moved from above it.

The alternative is aria-disabled="true" instead of disabled. MDN explains that it only tells assistive technology that the control is disabled (MDN, aria-disabled). The button keeps keyboard focus, so a screen reader user can find it and hear its description. The cost is a script, because the button still works: your code must ignore its clicks. pointer-events: none alone doesn’t stop a keyboard from pressing it.

Rule: A disabled control must look different from an enabled one and stay readable, and the page must say why it’s disabled.

A focus ring you can see in every theme

Keyboard users move through a page with Tab. A focus indicator is the visible mark on the element that will receive the next key press, usually a ring around it.

WCAG 2.2 has three success criteria about it:

  • 2.4.7 Focus Visible (AA) asks that the indicator be visible. It sets no size or color (Understanding 2.4.7). Removing it with outline: none is failure F78. Leaving the browser’s default ring is a sufficient technique, G165.
  • 1.4.11 Non-text Contrast (AA) covers the ring as a visual state: it needs 3:1 against the colors next to it.
  • 2.4.13 Focus Appearance (AAA), new in WCAG 2.2, asks for a ring at least as large as a 2 px line around the element. Its pixels need 3:1 between the focused and unfocused look (Understanding 2.4.13). The browser’s own ring is exempt if you haven’t changed it.

In drafts of WCAG 2.2, Focus Appearance was proposed at level AA, numbered 2.4.11. But it moved to AAA in May 2023 (Eggert, 2023), so older posts that call it AA are out of date. WCAG 2.2 became a W3C Recommendation on 5 October 2023 (What’s New in WCAG 2.2).

When :focus-visible shows the ring

:focus-visible matches when the browser decides that a ring helps. Selectors Level 4 gives the browser hints, not rules (Selectors 4, §9.4). It shows the ring after a key press, and on any element that takes typed input, such as a text field. But it doesn’t show the ring after a mouse click on a button.

So a click on a text field shows the ring, and a click on a button doesn’t. :focus-visible is Baseline widely available since 2024-09-14, and browsers use it for their own default ring. MDN adds one cost: a ring that appears for some input methods and not others can confuse some users (MDN, :focus-visible).

Pause and predict: Chrome draws its default ring on the “Save account” button. Does it pass WCAG? And is it easy to see?

Figure 6: before. Chrome’s default ring on the blue button, forced on for the screenshot.

Answer

It passes, because the site hasn’t changed it (G165). But it’s hard to see. In Chrome 157, getComputedStyle gives the ring’s color as #005fcc in the light theme. That’s 5.98:1 on white, but only 1.30:1 against the button’s #0078cd, so it merges with the fill. On the dark header, around the gear, the same blue is 2.66:1. Chrome also draws a thin white line next to it, which carries the contrast there.

The default ring is the browser’s color, not the site’s, and it looks different in every browser. But once you restyle it, you own its contrast. So the lab draws one ring and checks it everywhere it can appear:

/* excerpt from base.css */
/* One focus ring for every element, 2px outside it, so it never sits on the element's own fill */
:focus-visible {
  outline: 2px solid var(--color-focus);
  outline-offset: 2px;
}

The outline-offset leaves a 2 px gap of background between the element and the ring. So the ring never touches a button’s fill, and only the backgrounds of the page matter. The ring follows border-radius. Baseline lists that as widely available since 2025-09-27, and Safari 16.4 was the last browser to ship it.

The ring color is the accent, through its own token, so it can change later without changing links or buttons:

/* excerpt from tokens.css */
  --color-focus: var(--color-accent); /* 3:1 or more on surface, surface-alt and bar, both themes */

Here’s where the ring can sit, computed with the same ratio function:

Background Light theme, ring #0078cd Dark theme, ring #77c4ff
Surface (#ffffff, #222222) 4.60:1 8.43:1
Bar: header, footer, menu (#222222, #333333) 3.46:1 6.69:1
Surface-alt: code blocks (#e8e8e8, #333333) 3.75:1 6.69:1

Every cell is above 3:1, so 1.4.11 holds. The ring is 2 px thick all the way around, and its pixels change from the background color to the ring color. So the same numbers also meet 2.4.13 at AAA.

Figure 7: after. A 2 px ring in the accent color, 2 px outside the button. It is 4.60:1 on white.

When one color is not enough

A single ring color works here because the site has only a few flat backgrounds. But on a photo, or a page with many background colors, no single color reaches 3:1 everywhere. Technique C40 draws two rings: a light outline next to the element and a dark box-shadow outside it (C40). If the two colors are at least 9:1 apart, one of them reaches 3:1 on any solid background.

C40 also warns against a box-shadow alone. In forced colors mode, such as Windows’ contrast themes, browsers remove every box-shadow and replace outline and border colors with system colors (MDN, forced-colors). An outline survives that, but a shadow ring disappears. forced-colors is Baseline widely available since 2025-03-12.

A ring hidden behind a header

WCAG 2.2 added 2.4.11 Focus Not Obscured (Minimum), at AA. The focused element must not be entirely hidden by the author’s own content, such as a sticky header or a cookie banner (Understanding 2.4.11). scroll-padding on the page is one fix for a sticky header. Stashling’s header doesn’t stick, but its new menu covers the page when it’s open, and the menu section deals with that.

Rule: Draw the focus ring with outline and an offset, and check its color against every background it can touch, in every theme.

Targets big enough for a finger

Module 2 named target size: the size of the area that responds to a click or a tap. The drawn shape and the area that responds can differ. A hit area is the box that receives the click or tap, which can be larger than the icon or text you see.

WCAG 2.2 added success criterion 2.5.8, Target Size (Minimum), at level AA (Understanding 2.5.8). A target must be at least 24 × 24 CSS pixels, with five exceptions. The two that matter most here:

  • Spacing. A smaller target passes if a 24 px circle centered on it doesn’t overlap another target, or another small target’s circle.
  • Inline. A link inside a sentence passes, because its size comes from the text.

The others are an equivalent control elsewhere on the page, a control the browser draws, and a size that is essential to the information.

Success criterion 2.5.5, Target Size (Enhanced), from WCAG 2.1 in 2018, asks for 44 × 44 at level AAA (Understanding 2.5.5). The W3C page gives no derivation for 44. Platform guides use their own numbers:

Source Size Status
WCAG 2.5.8 (AA) 24 × 24 CSS px standard
WCAG 2.5.5 (AAA) 44 × 44 CSS px standard
Apple, iOS 44 × 44 pt default, 28 × 28 pt minimum convention (HIG, Accessibility)
Android 48 × 48 dp convention (Android, accessibility)
Parhi and others, 2006 9.2 to 9.6 mm for one thumb study of thumb use on small screens (MobileHCI 2006)

These answer different questions. 24 px is the floor for access; 44 px and 48 dp are comfortable sizes for a finger.

Pause and predict: open settings.html at 390 px in device mode, and run this in the console. Which elements will it list?

[...document.querySelectorAll("a, button, input, select")]
  .map((el) => [el, el.getBoundingClientRect()])
  .filter(([, r]) => r.width > 0 && (r.width < 24 || r.height < 24))
  .map(([el, r]) => `${el.outerHTML.slice(0, 40)}  ${r.width.toFixed(1)} x ${r.height.toFixed(1)}`)
Answer

Only the eight checkboxes in the snapshot table, each 13.0 × 13.0. The gear in the header is 24 × 25.6, exactly at the floor in width, and the nav links are 24.2 px tall.

But the checkboxes still pass 2.5.8 by the spacing exception. Their rows are 36 px apart at 1280 and about 106 px apart at 390, so 24 px circles around them never touch. Now run the same script on article.html, and it lists the links “settings page” and “download page”, each 20 px tall. They pass as inline targets.

So the site passes the AA floor. But the gear has no width to spare, and it’s the only way to reach the settings page. That’s why the lab gives it a 44 px hit area with the icon in the middle:

/* excerpt from tokens.css */
  /* Targets: WCAG 2.5.8 (AA) asks for 24px; 44px is WCAG 2.5.5 (AAA) and Apple's default */
  --target-min: 2.75rem; /* 44px */
/* excerpt from base.css */
.settings-link {
  margin-left: auto;
  display: grid; /* centers the 24px icon in a 44px box that takes the tap */
  place-items: center;
  min-inline-size: var(--target-min);
  min-block-size: var(--target-min);
}

The icon stays 24 px, so it still matches the set from Module 8. Only the box around it grows. Figures 8 and 9 show the header at 390 px with focus on the gear, because the focus ring outlines the hit area.

Figure 8: before. The gear’s hit area is the icon itself, 24 × 25.6 px.

Figure 9: after. The same icon in a 44 × 44 px hit area.

The cost is space. The header grows from 54 to 64 px at 1280, and a row of 44 px targets takes more room than a row of icons. The 13 px checkboxes stay as they are, because checkboxes belong to forms, which Module 10, Forms, Tables and the Words in Them, takes up.

Rule: Make every target at least 24 × 24 px, or space it so it passes; give the targets people use most, on touch screens, 44 px.

Depth: borders, shadows and fill

On a page, depth means that one surface seems to sit above another. Elevation is Material Design’s word for how far a surface seems to sit above the one below it. The web has three ways to show it: a border, a shadow and a difference in fill.

Pause and predict: Figure 10 shows one card three ways, in both themes. Which card looks raised above the page, and in which theme does that cue almost disappear?

Figure 10: one card three ways, in the light and the dark theme. Only the shadow card looks raised, and only in the light theme.

Answer

The shadow card, in the light theme. A border and a fill show where a surface ends, but not that it’s above anything. In the dark theme the shadow nearly disappears, because it’s dark on dark. The fill card shows the edge in both themes.

Here’s the demo’s CSS. It isn’t part of the lab, but it uses the lab’s tokens:

/* excerpt: color-calc/m9/depth.html, not part of the lab */
.card { inline-size: 14rem; padding: var(--space-4); border-radius: var(--radius-large); }
.border { border: 1px solid var(--color-border); }
.shadow { box-shadow: var(--shadow-raised); }
.fill { background: var(--color-surface-alt); }

The shadow token comes from Material Design 3’s web components, level 3 of its elevation scale (material-web, elevation):

/* excerpt from tokens.css */
  /* Depth: Material 3's level 3, a sharp key shadow and a soft ambient one */
  --shadow-raised: 0 1px 3px 0 rgb(0 0 0 / 0.3), 0 4px 8px 3px rgb(0 0 0 / 0.15);

Material draws every level with two shadows. The first is short and dark, like the shadow under an object from one strong light. The second is wide and faint, like the shadow from light that comes from every direction. Material’s levels are 0, 1, 3, 6, 8 and 12 dp, each with its own pair.

The dark theme needs numbers too. The key shadow alone, black at 30% over white, gives #b3b3b3, 2.10:1 against the page. But over #222222 it gives #181818, only 1.12:1. A darker shadow can’t fix that, because the page is already close to black.

So in a dark theme, a raised surface needs a lighter fill. Stashling’s bar is #333333 on a #222222 page in the dark theme, 1.26:1, and that’s what shows the menu’s edge there.

When is depth worth it? NN/g calls a three-dimensional look one of the strongest signs that something can be clicked (Loranger, 2015). Stashling’s feature cards can’t be clicked, so they keep a border and get no shadow. A shadow on them would promise an action that isn’t there.

The lab uses the shadow once, on the menu, which floats over the page. Two more costs apply. Forced colors mode removes all shadows, so a surface needs a border or a fill as well. And the right amount of shadow is a judgment; we found no study that gives a number.

Rule: Use a shadow for a surface that floats above the page, not for one that sits on it, and give it a lighter fill in the dark theme.

Corners, and one shape for every component

Corner radius is the radius of the curve that rounds a box’s corners, set in CSS with border-radius. Stashling’s buttons and cards have square corners today.

People seem to prefer curved objects. Bar and Neta showed 14 people 140 pairs of real objects and 140 pairs of meaningless patterns, each in a curved and a sharp-angled version. People liked the curved ones more (Bar and Neta, Psychological Science, 2006).

The study has 14 people and no interface elements. So it isn’t evidence that rounded buttons work better. We found no research on the right radius for a button, so the lab’s radius is a judgment, kept small.

One convention helps when boxes are nested. The inner radius equals the outer radius minus the space between them, so the two curves run parallel. Suppose a card has a 12 px radius and a button 12 px from its edge. Then the button needs square corners, and with 4 px between them, it would need 8 px.

The lab uses two radii, as tokens:

/* excerpt from tokens.css */
  /* Corners: a small radius for controls, a large one for the boxes around them */
  --radius-small: 0.25rem; /* 4px: buttons, status labels, links in the menu */
  --radius-large: 0.5rem;  /* 8px: cards, the sign-up form, the menu */

The menu is the one place with nesting: an 8 px panel with 4 px of padding holds links with 4 px corners. border-radius is Baseline widely available. But corner-shape, which draws other corner curves such as squircle, works only in Chrome and Edge 139 and later; elsewhere the reader sees a normal round corner.

Same button, same height

A component looks like one component only if every copy matches. Stashling has two kinds of button: links styled as buttons on the landing page and real <button> elements on the settings page.

Pause and predict: both kinds use .button, with padding: 10px 20px. Are they the same height at 390 px?

Answer

No. The links are 44.2 px tall and the buttons 40 px (47 and 41 px at 1280). A link takes the page’s line height, 1.5, from Module 4. But browsers give a <button> line-height: normal, which for Inter is smaller.

Module 2 taught text-box, which trims the space above and below the letters. If you trim it to the capitals and the baseline, a word has the same height whatever its line height. Then the padding alone sets the button’s height, and it can use the spacing scale:

/* excerpt from base.css */
.button {
  --fill: var(--color-accent); /* each kind of button sets its own fill */
  display: inline-block;
  background: var(--fill);
  color: var(--color-on-accent);
  border: none;
  border-radius: var(--radius-small);
  padding: var(--space-3) var(--space-5);
  text-box: trim-both cap alphabetic; /* the box ends at the top of the capitals and at the baseline */
  font-size: var(--step-0);
  text-decoration: none;
  cursor: pointer;
  transition: background-color var(--duration-fast) var(--ease-out);
}

Both kinds are now 35.75 px tall at 390 and 37.09 px at 1280. The padding is 12 px above and below the capitals, so the word sits in the optical middle. The transition line comes from the motion section.

text-box isn’t Baseline: Chrome 133 and Safari 18.2 support it, but Firefox doesn’t (web-features 3.46.0). Without it, buttons keep their line height. By arithmetic, a link button is then 48 px tall at 390 and a <button> about 43 px, so they still differ in Firefox. That’s a cost we accept, because nothing breaks.

The same idea applies to every state. The lab’s tokens give each component one radius, one ring and one timing, so a new component gets them by using the tokens. That’s a design-system convention, not research.

Rule: Build every copy of a component from the same tokens, and check that copies made from different HTML elements still match.

A menu for the nav on phones

At 390 px, Stashling’s nav wraps onto two lines, as Modules 7 and 8 left it. Nothing is lost, but the header is about 84 px tall and the links look scattered.

Figure 11: before. At 390 px the nav wraps onto two lines.

A menu hides the links behind a button. Module 8 gave the cost of that: in NN/g’s 2016 test, 44% of users used a hidden menu, against 89% for navigation they could see. So the button says “Menu” in words, and the menu appears only where the nav doesn’t fit.

In Chrome, at the default font size, the nav fits on one line from about 560 px. The breakpoint is 36rem, 576 px, so it moves with the reader’s font size, as Module 7 explained.

Three ways to build the menu, compared:

Approach What it gives Cost here
<details> and <summary> No script; the browser keeps the open state A closed <details> hides its content at every width. Showing the nav on wide screens needs ::details-content, Baseline newly available since 2025-09-16
popover with popovertarget No script; Esc and a click outside close it Newly available since 2025-01-27. An open popover sits in the top layer, so placing it under the header needs the header’s height or anchor positioning, which is not Baseline. Wide screens must undo the popover’s own styles
A button and 13 lines of JavaScript Uses only features that are Baseline widely available A script to maintain; Esc does not close it, and a click outside closes it only when focus was in the menu

We chose the script, as the course allows here. Without the script, the nav stays as it was, visible and wrapping, so a failed script loses nothing. Of the two no-script options, each needs a newly available feature and extra CSS to show the nav normally on wide screens.

The button goes after the logo in all four pages, hidden until the script runs:

<!-- excerpt: the same lines in index.html, article.html, signup.html and settings.html -->
  <script src="menu.js" defer></script>
</head>
<body>
  <header class="site-header">
    <a class="logo" href="index.html">Stashling</a>
    <button class="menu-button" type="button" hidden>Menu</button>
    <nav>

The script, menu.js, shows the button, keeps aria-expanded up to date, and closes the menu when focus leaves it. This is the whole file:

// Turns the nav into a menu on narrow screens (base.css decides where).
// Without this script, the Menu button stays hidden and the nav stays visible.
const button = document.querySelector(".menu-button");
const nav = button.nextElementSibling;
button.hidden = false;
button.ariaExpanded = "false";
button.addEventListener("click", () => {
  button.ariaExpanded = button.ariaExpanded === "true" ? "false" : "true";
});
// Close when focus leaves the menu, so the open menu never covers the focused element (WCAG 2.4.11)
nav.addEventListener("focusout", (event) => {
  if (event.relatedTarget !== button && !nav.contains(event.relatedTarget)) button.ariaExpanded = "false";
});

aria-expanded tells a screen reader whether the menu is open, and the CSS uses the same attribute. button.ariaExpanded is ARIA attribute reflection, Baseline widely available since 2026-04-24.

The last three lines matter for 2.4.11. The open menu covers the top of the page. So without them, a keyboard user could Tab past the last link into the “Name” field, which would be hidden under the menu.

The CSS draws the menu as a panel under the header, with the bar’s color, the shadow token and 48 px rows:

/* excerpt from base.css */
/* The Menu button. It stays hidden until menu.js runs, so without the script the nav stays visible */
.menu-button {
  min-block-size: var(--target-min);
  padding-inline: var(--space-3);
  border: 1px solid currentColor;
  border-radius: var(--radius-small);
  background: none;
  color: inherit;
  font-size: var(--step-0);
  cursor: pointer;
}

/* Below 36rem the nav does not fit on one line (it needs 560px), so it becomes a menu */
@media (width < 36rem) {
  .site-header {
    position: relative;
  }

  .menu-button[aria-expanded] + nav {
    position: absolute;
    top: 100%;
    inset-inline: var(--page-margin);
    z-index: 1;
    flex-direction: column;
    gap: 0;
    padding: var(--space-1);
    border-radius: 0 0 var(--radius-large) var(--radius-large);
    background: var(--color-bar);
    box-shadow: var(--shadow-raised);
  }

  .menu-button[aria-expanded] + nav a {
    padding: var(--space-3);
    border-radius: var(--radius-small); /* the menu's 8px minus its 4px padding */
  }

  .menu-button[aria-expanded="false"] + nav {
    visibility: hidden; /* also takes the links out of the tab order */
  }
}

@media (width >= 36rem) {
  .menu-button {
    display: none;
  }
}

Notice three things:

  1. Every menu rule needs [aria-expanded], which only the script sets. So without the script, none of them apply.
  2. visibility: hidden hides the closed menu from the eye, from Tab and from screen readers. opacity: 0 alone would leave invisible links in the tab order.
  3. The .menu-button rule sets no display, so the hidden attribute still hides it until the script runs.

The media query range syntax, width < 36rem, is Baseline widely available since 2025-09-27.

Pause and predict: the open menu uses the bar’s color and the shadow token. In which theme will its edge against the page be easier to see?

Answer

In the light theme. There the panel is #222222 on a white page, 15.91:1, with a shadow below it. In the dark theme it’s #333333 on #222222, 1.26:1, and the shadow is dark on dark. So the fill does the work there.

Figure 12: after, with the menu open. One header line, a labeled button, and 48 px rows.

The structure of the navigation, what it contains and where Settings belongs, is Module 11’s subject, Usability: Conventions, Navigation and Quick Tests.

Rule: Hide navigation behind a button only where it doesn’t fit, label the button with a word, and keep the links reachable when the script fails.

Small motion: duration and easing

The menu now appears in a single frame. A short movement can show where it came from. But a long or fast one can annoy people, or make some of them sick.

Pause and predict: one menu opens with transition: all 600ms ease-in. Another opens with opacity and transform over 200 ms with an ease-out curve. Which one feels slower to open, and why?

Answer

The 600 ms ease-in, by far. It starts slowly, so after 200 ms it has covered 16% of its way, and after 400 ms about half. The 200 ms ease-out has covered 58% after 50 ms and 84% after 100 ms. Figure 13 plots both.

A duration is how long a transition or animation takes from start to end. Easing is the curve that sets how fast a value changes at each moment of that time. Ease-out starts fast and slows to a stop; ease-in starts slowly and ends fast.

Figure 13: the same distance in two timings. The dots mark every 50 ms. After 100 ms, the 200 ms ease-out has covered 84% of its way, and the 600 ms ease-in 4%.

The numbers in Figure 13 come from color-calc/m9/motion.mjs, which solves each cubic-bezier() curve as CSS defines it. A still image can’t show motion, so open any lab page in a window narrower than 576 px and click Menu.

Durations are conventions

Three design sources give durations. None of them cites an experiment for its numbers:

Source Durations Easing
NN/g, 2020 (Laubheimer) Most 100 to 500 ms; simple feedback about 100 ms; a modal 200 to 300 ms; entrances slightly longer than exits Ease-out by default
Material Design 1 (2014 to 2017) About 300 ms on mobile; 150 to 200 ms on desktop; more than 400 ms “may feel too slow” Standard cubic-bezier(0.4, 0, 0.2, 1); decelerate (0, 0, 0.2, 1)
Material Design 3, web tokens (material-web) Steps from 50 to 1000 ms: short 50 to 200, medium 250 to 400 Standard cubic-bezier(0.2, 0, 0, 1)

The author of the NN/g article calls its numbers a rule of thumb. The sources agree on the range, and that agreement is the evidence: practice, not a study. The lab takes two durations and Material 1’s decelerate curve:

/* excerpt from tokens.css */
  /* Motion. The numbers are conventions (NN/g, Material Design), not research findings */
  --duration-fast: 100ms;   /* feedback, such as a hover color */
  --duration-medium: 200ms; /* a menu that opens */
  --ease-out: cubic-bezier(0, 0, 0.2, 1); /* starts at full speed, slows to a stop */

Why ease-out for something that enters? Objects in the world speed up and slow down, so something that arrives fast and settles looks like it came from somewhere. That’s the argument from animation practice, not a measured result. Ease-in suits something that leaves, because it gets out of the way at the end.

The menu animates two properties, not all, because all animates every property that changes, including ones added to the rule later. The menu fades and slides down 0.5rem:

/* excerpt from base.css, inside @media (width < 36rem) */
  .menu-button[aria-expanded] + nav {
    /* … the rules from the menu section … */
    transition:
      opacity var(--duration-medium) var(--ease-out),
      transform var(--duration-medium) var(--ease-out);
  }

  .menu-button[aria-expanded="false"] + nav {
    visibility: hidden; /* also takes the links out of the tab order */
    opacity: 0;
    transform: translateY(-0.5rem);
    /* on closing, stay visible until the fade ends */
    transition:
      opacity var(--duration-medium) var(--ease-out),
      transform var(--duration-medium) var(--ease-out),
      visibility 0s var(--duration-medium);
  }

The browser uses the transition of the state it’s moving to. Opening uses the first rule, which doesn’t list visibility, so the menu becomes visible at once and fades in. Closing uses the second, where visibility waits 200 ms, so the menu fades out before it’s hidden. Transitions and cubic-bezier() are Baseline widely available.

Reduced motion

A vestibular disorder is a condition of the inner ear and brain that affects balance. For people who have one, movement on a screen, such as zooming, parallax or large slides, can cause dizziness, nausea and headaches. WCAG names those three symptoms in 2.3.3.

Operating systems have a setting to reduce motion, and CSS reads it as prefers-reduced-motion: reduce (MDN). On macOS it’s in Accessibility, Display. On Windows 11 it’s Accessibility, Visual effects, Animation effects. iOS has Accessibility, Motion, and Android 9 and later has Remove animations. The media feature is Baseline widely available since 2022-07-15.

WCAG 2.2 success criterion 2.3.3, Animation from Interactions, at AAA, asks that motion started by an interaction can be turned off, unless it’s essential (Understanding 2.3.3). But its definition of motion excludes changes of color, blur and opacity that don’t change size, shape or position.

So “reduce” doesn’t have to mean “remove”. MDN suggests toning motion down, for example by replacing a movement with a fade. The lab keeps the fade and drops the slide:

/* excerpt from base.css */
/* Reduced motion: the menu fades but does not slide. A fade is not motion under WCAG 2.3.3 */
@media (prefers-reduced-motion: reduce) {
  .menu-button[aria-expanded="false"] + nav {
    transform: none;
  }
}

Emulate reduced motion in Chrome, and opening the menu runs only the opacity transition. The button’s hover color still fades over 100 ms, which is a color change and not motion.

Recent CSS adds more. linear() approximates springs and bounces with many points, Baseline widely available since 2026-06-11. @starting-style and transition-behavior: allow-discrete animate an element that appears from display: none; both are newly available since 2024-08-06. The lab needs none of them. Without the menu’s motion, the menu would open in one frame, as it does with motion turned off.

Rule: Keep interface motion between about 100 and 300 ms, ease out what enters, animate named properties only, and replace movement with a fade when the reader asks for reduced motion.

Components and states: choices and costs

Decision Choice in the lab Cost or limit Choose something else when
Link signifier Accent color and underline Noisy in text with many links Links in a list or a header, where position shows them: no underline
Hover Only in @media (hover: hover) Touch readers get no hover cue Never on touch; hover is supplemental anyway
Pressed Moves 1px Easy to miss A pressed fill that keeps 4.5:1 in both themes
Disabled disabled, gray fill, reason next to it Not focusable; no reason for screen reader users who never reach it The control must be found by keyboard: aria-disabled and a script; or keep it enabled and explain on press
Focus ring One 2px outline, 2px offset, accent color One color must pass on every background Photos or many backgrounds: C40’s two-color ring
Target size 44px for the gear and the menu, 24px floor elsewhere Takes space A dense desktop tool: 24px with spacing
Depth Shadow on the floating menu only; border on cards Shadows vanish in dark themes and forced colors A dark-first design: lighter fills for raised surfaces
Corners 4px controls, 8px boxes A judgment; no research gives a number A brand with its own shape language
Menu Button and 13 lines of script No Esc; a click outside closes it only when focus was in it Popover once you can rely on it, with anchor positioning
Motion 100 and 200 ms, ease-out, fade only on reduce Conventions, not findings A large panel or page change: up to about 300 to 400 ms

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.

  • WCAG 2.2 became a W3C Recommendation on 5 October 2023. It added 2.4.11 Focus Not Obscured (AA), 2.4.13 Focus Appearance (AAA) and 2.5.8 Target Size (Minimum) (AA), and removed 4.1.1 Parsing.
  • :focus-visible became Baseline widely available on 2024-09-14. Outlines that follow border-radius became widely available on 2025-09-27.
  • forced-colors became widely available on 2025-03-12, and the media query range syntax on 2025-09-27.
  • ARIA attribute reflection, such as button.ariaExpanded, became widely available on 2026-04-24, and linear() easing on 2026-06-11.
  • popover is newly available since 2025-01-27, ::details-content since 2025-09-16, and same-document view transitions since 2025-10-14. @starting-style and transition-behavior are newly available since 2024-08-06.
  • Not Baseline: text-box (no Firefox), anchor positioning (Chrome 157 and Safari 27, no Firefox), corner-shape (Chrome and Edge 139 and later) and interpolate-size (Chrome and Edge 129 and later).
  • Material Design 3 Expressive, with spring-based motion, was announced in May 2025. News coverage says it shipped on Pixel phones with Android 16 in September 2025; we couldn’t open Google’s own page.

border-radius, box-shadow, transitions, cubic-bezier(), text-underline-offset, prefers-reduced-motion and the hover media feature have been widely available for years.

Online tools for this step

All three were checked on 2026-11-18.

  • CSS Shadow Palette Generator, by Josh W. Comeau. It makes three elevation levels as layered box-shadow values in custom properties. You set the light’s position, the background color, the shadow’s tint and the number of layers.

Limit: three fixed levels, tuned to one background, with no dark theme or forced colors. It runs in the browser with no account; the page states no price. Chrome DevTools has a shadow editor in the Styles pane, but it edits one layer at a time.

  • cubic-bezier.com, by Lea Verou. You drag the two control points of a cubic-bezier() curve, preview the motion, compare it with presets and share it by link. Limit: it makes cubic Bézier curves only, not linear() springs. Its source is MIT licensed. Chrome and Firefox DevTools both have an easing editor on transition-timing-function values.

  • Linear() Easing Generator, by Jake Archibald. It turns a JavaScript easing function, such as a spring or a bounce, or an SVG path, into a CSS linear() value, with a preview. Limit: the output approximates the curve, and more points mean more accuracy and a longer value. linear() has been widely available only since June 2026, so older browsers ignore it. Its source is Apache-2.0 licensed. DevTools has no equivalent.

Check yourself

Critique: a team’s admin page

A team’s admin page has a white background and body text #333333. Links are #2f6fb0, with no underline. The main button is blue with white text. Its disabled version, used until a form is complete, is the same blue at 90% opacity.

To remove “the ugly blue ring”, the CSS has *:focus { outline: none; }. Buttons get box-shadow: 0 0 0 2px #ffffff on focus instead. A toolbar holds three 16 × 16 px icon buttons with 4 px between them. A side menu opens with transition: all 600ms ease-in and has no reduced-motion rule. On the dashboard, every card has a large shadow, though only some cards open anything. In the dark theme, the cards have the same fill as the page.

Hint 1

Compute the link against white and against the text. Then think about what the ratios multiply to.

Hint 2

Where is a white ring drawn, and what color is next to it? What happens to box-shadow in forced colors mode?

Hint 3

Draw a 24 px circle around each toolbar button. How far apart are their centers?

Hint 4

What does a shadow promise, according to NN/g? What happens to a black shadow on a near-black page?

Answer
  1. The link is 5.22:1 on white but only 2.42:1 against the text, so color alone fails 1.4.1 (F73). With #333333 text, which is 12.63:1 on white, no color can pass G183: a link at 4.5:1 on white is at most 2.81:1 against the text. Underline the links.
  2. A disabled button at 90% opacity looks enabled. So give it a neutral fill and readable text, and put the reason next to it, or keep it enabled and explain what is missing when someone presses it.
  3. outline: none is failure F78. The white shadow ring sits outside the button on a white page, 1:1, so focus is invisible, and forced colors mode removes the shadow anyway. Use a 2px outline with an offset, in a color that reaches 3:1 on white.
  4. The icon buttons are 16 px with 4 px gaps, so their centers are 20 px apart. So 24 px circles around them overlap, and they fail 2.5.8. Give each a 24 px hit area at least, or 44 px if the page is used on phones.
  5. 600 ms with ease-in feels slow: 16% of the way after 200 ms. all animates every changing property. Use opacity and transform over about 200 ms with ease-out, and a fade without the slide under prefers-reduced-motion: reduce.
  6. A shadow is a strong sign that something can be clicked, so cards that open nothing should lose it and keep a border. In the dark theme the shadows nearly vanish and the cards blend into the page; give raised cards a lighter fill there.

Review questions

  1. Why does a Stashling link need its underline in the dark theme but not in the light theme, if you count contrast alone?
  2. The dark theme’s pressed state was going to mix 25% black into the button. What goes wrong, and what did the lab do instead?
  3. Why does the lab draw the focus ring with outline and outline-offset, and not with box-shadow?
  4. What does WCAG 2.5.8 ask, and why do the table’s 13 px checkboxes pass it?
  5. Under prefers-reduced-motion: reduce, what does the menu keep, and why does that meet WCAG 2.3.3?
Answers
  1. In the light theme the link is 3.46:1 against the text and 4.60:1 on white, which meets G183. But in the dark theme it’s 1.54:1 against the text, and no color can pass both checks, because the text is only 12.98:1 on its surface.
  2. The fill moves toward the dark text, so the text drops to 4.01:1, below 4.5:1. The lab moves the button down 1px instead and leaves the color.
  3. The offset keeps the ring off the button’s fill, so only the page backgrounds matter for its 3:1. Forced colors mode removes box-shadow but keeps outlines.
  4. A target of at least 24 × 24 CSS px, unless an exception applies. The checkboxes pass by spacing: their rows are at least 36 px apart, so 24 px circles around them don’t overlap.
  5. It keeps the fade and drops the 0.5rem slide. WCAG’s definition of motion animation excludes opacity changes that don’t change size, shape or position.

The lab: components that show what they do

In about 15 minutes, you make links and the disabled button honest, draw one focus ring, enlarge the gear’s hit area, and give components one shape. Then you turn the phone nav into a menu that moves gently. Start from the module-08 folder and reload after each step. The finished files are in the module-09 folder of the course repository.

Step 1: make links look like links

Why: the links in body text have no signifier (see “Links that look like links”).

In tokens.css, add this line after --color-on-accent:

  --color-link: var(--color-accent); /* one blue for everything you can act on */

In base.css, replace the a and a:hover rules with these four rules:

a {
  color: var(--color-link);
  text-underline-offset: 0.2em; /* clear of the letters, so g and y stay readable */
}

a:hover {
  text-decoration-thickness: 2px;
}

/* The nav and the logo keep the bar's colors; their place in the header says they are links */
.site-header a {
  color: inherit;
  text-decoration: none;
}

.site-header a:hover {
  text-decoration: underline;
}

In the .button rule, add text-decoration: none; before cursor: pointer;. Then delete the text-decoration: none; line from .button:hover.

What you should see: Figure 3 instead of Figure 2 on article.html. On the landing page, the three links next to “Download 2.4” turn blue. The header doesn’t change.

Step 2: make the disabled button look disabled

Why: “Restore selected” looks like a button that works (see “A disabled button that looks disabled”).

In base.css, replace the .button:hover rule with these two rules:

/* Only where a pointer can hover: on a touch screen, :hover sticks after a tap */
@media (hover: hover) {
  .button:hover:not(:disabled) {
    background: color-mix(in oklab, var(--fill), black 15%);
  }
}

/* Disabled: no accent fill, so it no longer looks like the buttons that work */
.button:disabled {
  --fill: var(--color-surface-alt);
  color: var(--color-muted);
  cursor: not-allowed;
}

In settings.html, delete the line <p>Select a snapshot to restore its files.</p> above the table. Replace the “Restore selected” button with these two lines:

      <p id="restore-hint">Select a snapshot to restore its files.</p>
      <button class="button" type="button" disabled aria-describedby="restore-hint">Restore selected</button>

What you should see: Figure 5 instead of Figure 1. Hover over the gray button: it doesn’t darken.

Step 3: draw one focus ring

Why: the browser’s ring merges with the blue buttons (see “A focus ring you can see in every theme”).

In tokens.css, add this line after --color-link:

  --color-focus: var(--color-accent); /* 3:1 or more on surface, surface-alt and bar, both themes */

In base.css, add this rule after .site-header a:hover:

/* One focus ring for every element, 2px outside it, so it never sits on the element's own fill */
:focus-visible {
  outline: 2px solid var(--color-focus);
  outline-offset: 2px;
}

What you should see: press Tab on settings.html until “Save account” has focus. It looks like Figure 7, not Figure 6. Keep pressing Tab: the table’s scroll box and the red button get the same ring. Click a button with the mouse, and no ring appears; click a text field, and it does.

Step 4: give the gear a 44 px hit area

Why: the gear is exactly 24 px wide, and it’s the only way to the settings page (see “Targets big enough for a finger”).

In tokens.css, add an empty line after --icon-size, then these lines:

  /* Targets: WCAG 2.5.8 (AA) asks for 24px; 44px is WCAG 2.5.5 (AAA) and Apple's default */
  --target-min: 2.75rem; /* 44px */

In base.css, replace the .settings-link rule with this one:

.settings-link {
  margin-left: auto;
  display: grid; /* centers the 24px icon in a 44px box that takes the tap */
  place-items: center;
  min-inline-size: var(--target-min);
  min-block-size: var(--target-min);
}

What you should see: tab to the gear at 390 px. The ring is a 44 px square, as in Figure 9. The header is 64 px tall at 1280.

Step 5: one shape for every component

Why: buttons built from <a> and <button> have different heights, and corners differ from component to component (see “Corners, and one shape for every component”).

In tokens.css, add an empty line after --target-min, then these lines:

  /* Corners: a small radius for controls, a large one for the boxes around them */
  --radius-small: 0.25rem; /* 4px: buttons, status labels, links in the menu */
  --radius-large: 0.5rem;  /* 8px: cards, the sign-up form, the menu */

In base.css, in the .button rule, replace padding: 10px 20px; with these three lines:

  border-radius: var(--radius-small);
  padding: var(--space-3) var(--space-5);
  text-box: trim-both cap alphabetic; /* the box ends at the top of the capitals and at the baseline */

Then add this rule right after the .button rule:

/* Pressed: the button moves down 1px, like a key */
.button:active:not(:disabled) {
  transform: translateY(1px);
}

Add border-radius: var(--radius-large); after the border line of .feature in index.css and of .signup-form in signup.css. Add border-radius: var(--radius-small); after the padding line of .status in settings.css.

What you should see: every button has small round corners and is 35.75 px tall at 390, on every page. Run [...document.querySelectorAll(".button")].map((b) => b.getBoundingClientRect().height) on index.html and settings.html to check. The cards, the sign-up form and the status labels have round corners.

Step 6: turn the nav into a menu on phones

Why: the nav wraps onto two lines below 560 px (see “A menu for the nav on phones”).

In tokens.css, add an empty line after --radius-large, then these lines:

  /* Depth: Material 3's level 3, a sharp key shadow and a soft ambient one */
  --shadow-raised: 0 1px 3px 0 rgb(0 0 0 / 0.3), 0 4px 8px 3px rgb(0 0 0 / 0.15);

In all four HTML files, add <script src="menu.js" defer></script> after the last <link> in the head. Add <button class="menu-button" type="button" hidden>Menu</button> after the logo link, as in the excerpt in the menu section.

Create menu.js next to the HTML files, with the 13 lines shown in the menu section.

In base.css, add the .menu-button rule and the two media queries from the menu section after the .site-header nav rule.

What you should see: at 390 px, the header is one line with a “Menu” button, as in Figure 12 once you click it. Click again and the menu closes. Tab through the open menu and past its last link: the menu closes. At 1280 nothing changes. Turn off JavaScript in DevTools, and the nav wraps as before, with no button.

Step 7: let the menu move, gently

Why: the menu appears in one frame, with no sign of where it came from (see “Small motion: duration and easing”).

In tokens.css, add an empty line after --shadow-raised, then these lines:

  /* Motion. The numbers are conventions (NN/g, Material Design), not research findings */
  --duration-fast: 100ms;   /* feedback, such as a hover color */
  --duration-medium: 200ms; /* a menu that opens */
  --ease-out: cubic-bezier(0, 0, 0.2, 1); /* starts at full speed, slows to a stop */

In base.css:

  1. In .button, add transition: background-color var(--duration-fast) var(--ease-out); after cursor: pointer;.
  2. In the .menu-button[aria-expanded] + nav rule, add the transition from the motion section after box-shadow.
  3. In the .menu-button[aria-expanded="false"] + nav rule, add the opacity, transform and transition lines from the motion section after visibility: hidden;.
  4. After the @media (width < 36rem) block, add the @media (prefers-reduced-motion: reduce) rule from the motion section.

What you should see: at 390 px, the menu fades in and slides down 8 px in 200 ms, and fades out when it closes. In DevTools, open the Rendering tab and set “Emulate CSS media feature prefers-reduced-motion” to reduce: the menu fades without sliding. Set --duration-medium: 600ms for a moment to see the movement slowed down.

Step 8: check both themes and both widths

Why: every color and size in this module was checked in two themes, and the result should match.

Look at all four pages at 390 and 1280 px, in the light and the dark theme. Tab through settings.html from the top.

What you should see: at 320 px, document.documentElement.scrollWidth is still 320 on all four pages. In the dark theme, links are light blue and underlined, the focus ring is light blue, and the disabled button is dark gray with gray text. On settings.html at 390 in the dark theme, with focus on “Save account”, the page looks like Figure 14.

Figure 14: after the lab, in the dark theme at 390 px. A menu button, a 44 px gear, and one focus ring.

Optional: apply it to a page of your own

Pick a page of your own with links, buttons and a form.

  1. Search your CSS for text-decoration: none on a, and for outline: none. Underline links in text, and replace removed outlines with one :focus-visible ring.
  2. Compute your link color against your text and your background, and your ring color against every background it can touch, in every theme.
  3. Run the target script from this module at 390 px, and decide which small targets pass by spacing and which need a larger hit area.
  4. List your buttons’ states, and check that disabled looks disabled and that every hover is inside @media (hover: hover).
  5. Find every transition: all and every duration over 400 ms, and add a prefers-reduced-motion rule.

Module 9 cheat sheet

Links      underline in text; color alone needs 3:1 vs text and 4.5:1 vs bg
States     enabled, hover (@media (hover: hover)), focus, pressed, disabled
Disabled   no accent fill, readable text, the reason next to it
Focus      outline: 2px solid; outline-offset: 2px; 3:1 on every bg it touches
Targets    24px floor (2.5.8, or by spacing); 44px for touch (--target-min)
Depth      shadow only for floating surfaces; lighter fill in the dark theme
Corners    --radius-small 4px, --radius-large 8px; inner = outer - padding
Motion     100 to 200 ms, ease-out to enter, named properties, conventions
Reduce     prefers-reduced-motion: keep the fade, drop the movement

Module 10, Forms, Tables and the Words in Them, starts with a sign-up form that shows every error only after submit and a settings table with ragged numbers.

Sources

Standards and W3C guidance:

CSS and ARIA references:

Design guidance, cited for what it recommends:

Research, cited with the strength of its evidence:

Browsers:

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

The contrast ratios come from color-calc/m9/m9.mjs and the timing numbers from color-calc/m9/motion.mjs. The measured sizes, such as button heights and the nav’s width, come from runs of the lab pages in headless Chrome 157 on macOS, with a 16 px default font size. Your numbers will differ with other browsers and settings.