Web Design for Developers / Module 08

Module 8: Images and Icons

Fix a squeezed photo and four icons that do not match, then crop, dim and label images and icons with reasons and computed contrast.

This is the landing page of Stashling, the course’s sample site, as Module 7 left it, 1280 pixels wide.

Figure 1: the landing page at 1280 pixels. The photo is squeezed flat, and the four icons differ in size, weight and color.

A reader would say the picture looks broken and the icons look borrowed. The round clock is an oval, and the four icons look like they come from four different sites. Open it in the dark theme, and the photo is the brightest thing on the page, while the blue cloud almost disappears.

This module is about images and icons. It covers what each image on a page is for, how to keep its shape at every width and how to put text on it. Then it makes the icons look like one family. Each part ends as CSS or HTML in the sample site.

After this module, you can:

  • say what job an image does on a page, and decide when a page is better with no image
  • keep a photo’s shape at every width with object-fit and the image’s own size, and choose which part of it stays in view
  • put text over a photo and show, with a computed ratio, that it meets WCAG’s 4.5:1
  • write alt text from the reason an image is on the page
  • replace mixed icons with icons from one family, at one size and color, and give each icon a word beside it

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

A photo squeezed into a box it does not fit

Pause and predict: look at Figure 1. What makes the photo look wrong, and which CSS do you suspect? Then name every way the four icons differ from each other.

Answer

The photo file is 1200 × 800 pixels. index.css gives it width: 100%; height: 300px, so at 1280 the box is 1152 × 300. The browser scales the width by 0.96 and the height by 0.375, so circles are drawn 0.375 / 0.96 = 0.39 times as tall as they are wide. But on a 390-pixel phone the box is 358 × 300, and the photo is stretched the other way, 1.26 times too tall.

The icons differ in four ways. Their sizes are 24, 48, 32 and 40 px. One is filled, three are outlines.

The outlines are drawn 1, 4 and 3.33 px wide. A 3-unit line in a 24-unit drawing shown at 32 px is 3 × 32 / 24 = 4 px. The cloud is pure blue, #0000ff, while the others use the text color.

The photo problem comes from two common lines of CSS, a width of 100% and a fixed height. The icon problem is four SVGs copied from four places. Before you fix either, ask whether the page needs the image at all.

Every image needs a job

NN/g’s eyetracking work found that people look at images that carry information for their task, such as products and real people. But they ignore images that only add a look, and generic photos that could sit on any site (Nielsen, NN/g, 2010).

On one site, users spent about 10% more time on real staff photos than on staff bios that took 316% more space. On an Amazon category page, about 18% of viewing time went to photos and 82% to text. But the article gives gaze plots of single users, with no participant count, so treat its numbers as observations without a measured size of effect.

W3C’s accessibility tutorials name the two kinds that matter here (WAI, Informative images). An informative image is an image that carries information the page needs, such as a product photo or a chart. A decorative image is an image that only adds a look, so removing it loses no information. WAI points out that the same picture can be either, depending on why the author put it there.

A stock photo is a generic photo from a library, made to fit many sites. Its cost is that readers have seen ones like it before, and NN/g found they skip such photos.

This course sorts the job of an image into four kinds. That’s our own frame, built from the sources above; no standard defines it:

Job Example Informative or decorative
Show the thing a product photo, a screenshot of the app informative
Show the people the real team, a real customer informative
Explain a diagram, a chart informative
Set a mood a sunset, a desk, people at a laptop usually decorative

The first three are content. A mood image costs attention and space, so it’s the first one to cut.

A page is better with no image when the only image you have is generic, or when it pushes the main action down. NN/g’s scrolling study, from Module 7, found 57% of viewing time above the fold (Fessenden, NN/g, 2018). It’s also better with none when no true image of the thing exists.

Stashling’s photo is a mood image of a desk with a laptop and a drive. It repeats the tagline above it, “Back up your home folder to any storage you own.” But the lab keeps it, because it sits below the Download button and doesn’t push it down. A view of Stashling itself would be content, and for a command-line tool that’s its output, which the download section already shows as text.

Rule: Give every image one of the four jobs before you place it, and cut the mood image first when space or attention is short.

Choosing and cropping a photo

Most photos are wider or taller than the box they end up in, so you choose which part to keep.

The focal point is the part of a photo the eye should land on, such as a face or the product. A crop is the part of a photo you keep inside the frame. In Stashling’s photo, the focal point is the laptop and the drive beside it. The window, the clock and the mug are background.

A good crop keeps the focal point and enough space around it. If you shrink a wide shot to fit a phone, the focal point gets too small, so a phone often needs a tighter crop. Art direction is serving a differently cropped image for each layout, so the focal point stays large enough (MDN, Responsive images).

Art direction is HTML, a <picture> element with one <source media="…"> per layout:

<!-- excerpt: art direction, not part of the lab -->
<picture>
  <source media="(width >= 40rem)" srcset="images/hero-wide.webp">
  <img src="images/hero-close.webp" width="1200" height="800" alt="">
</picture>

It must be HTML, MDN explains, because the browser starts to fetch images before it’s read the CSS. <picture> is Baseline widely available since 2018-09-21 (web-features 3.46.0).

The cheaper choice is one file and a crop in CSS, which the next section shows. Its cost is that the crop changes with the box’s shape. So art direction wins when the focal point must be framed differently on a phone, such as a portrait close-up.

When you choose photos, three habits help:

  • Real over stock. NN/g found readers look at real people and products, and skip generic photos.
  • Specific enough to tell items apart. A product photo should show what makes this product different.
  • One treatment for a set. The same shape, and the same warmth of color, for every photo in a row. It’s a convention; we found no study behind it.

object-fit keeps a photo’s shape

An <img> is a replaced element: its content comes from a file, and CSS sizes the box around it. The property object-fit decides how the picture fills that box (MDN, object-fit).

The aspect ratio of an image or a box is its width divided by its height, written as two numbers such as 3:2. Stashling’s photo is 1200 × 800, so its aspect ratio is 3:2. But the box in Figure 1 is 1152 × 300, about 3.84:1.

Figure 2 shows the same photo in four boxes of 290 × 120 pixels, one value of object-fit each.

Figure 2: four values of object-fit in the same 290 × 120 box. Only fill changes the photo’s shape.

/* excerpt: the demo page for Figure 2, not part of the lab */
.demo img { display: block; width: 100%; height: 120px; background: var(--color-surface-alt); }
.fill { object-fit: fill; }
.contain { object-fit: contain; }
.cover { object-fit: cover; }
.none { object-fit: none; }

The values, from CSS Images Level 3 (Editor’s Draft):

  • fill, the initial value, stretches the picture to the box. It’s the only value that distorts.
  • contain shows the whole picture and leaves empty bars, which show the element’s background.
  • cover fills the box and crops what does not fit.
  • none keeps the picture’s natural size and crops it. scale-down uses whichever of none and contain gives the smaller picture.

So the opening problem is fill, the default, in a box of another shape. Use contain when nothing may be cut, such as a logo, a screenshot or a diagram. Use cover for a photo whose edges you can lose.

Pause and predict: you add only object-fit: cover to the 1152 × 300 box. Which part of the photo is lost, and how much of its height stays in view?

Answer

The photo is scaled until it covers the box: 1152 px wide, so 768 px tall. Only 300 of those 768 px fit, 39% of the height. By default the crop is centered, so the top and the bottom are lost. The band keeps rows 244 to 556 of the 800-pixel file, which cuts off the top of the window and the clock, and the whole desk.

The photo’s own shape, with a ceiling

A fixed height is the cause of the problem, because the right height depends on the width. So the lab lets the height follow the photo’s shape and gives it a ceiling.

First, the <img> gets the file’s size as attributes:

<!-- excerpt from index.html -->
<img src="images/hero.webp" width="1200" height="800" alt="">

The HTML specification turns these two attributes into aspect-ratio: auto 1200 / 800 for the image (HTML, Rendering). So with height: auto in CSS, the box takes the photo’s 3:2 shape at any width, before the file has loaded. The alt="" is the subject of a later section. This mapping is Baseline widely available since 2024-03-20 (Chrome 79, Firefox 71, Safari 15).

Then the CSS:

/* excerpt from index.css */
.hero img {
  width: 100%;
  height: auto;             /* the photo's own 3:2 shape, from its width and height attributes */
  max-block-size: 20rem;    /* never taller than 320px, so a wide screen gets a band */
  object-fit: cover;        /* fill the box and crop what does not fit; never squeeze */
  object-position: 50% 63%; /* keep the laptop and the drive inside the band */
}

On a phone the box is 3:2, and the whole photo shows. But once the content column is wider than 480 px, 3:2 would be taller than 320 px. So from there the box stays 320 px tall, a band, and cover crops the photo instead of squeezing it.

object-position chooses the crop. Its initial value is 50% 50%, the center, and it uses the same syntax as background-position (CSS Images 3). A percentage lines up that point of the picture with the same point of the box.

At 1280, the photo is drawn 768 px tall in a 320 px band, so 448 px are cropped. At 63%, 282 px come off the top, and the band shows rows 294 to 627 of the 800-pixel file. The clock ends at row 285 and the laptop starts at row 300, so the laptop is whole and the clock is gone.

Figures 3 and 4 show the same crop of the page before and after, at 1280.

Figure 3: before. A 1200 × 800 photo forced into 1152 × 300.

Figure 4: after. The same photo, cropped to a band with its focal point inside.

At 390, the change goes the other way: the photo was stretched tall, and now it shows whole.

Figure 5: before, at 390 px. The box is taller than the photo’s shape.

Figure 6: after, at 390 px. The box takes the photo’s 3:2 shape, so nothing is cropped.

The cost is that the crop changes with the width. At 900 px the band shows rows 225 to 668, so the bottom of the clock appears at its top edge. So check a crop at several widths in device mode, or use art direction when one crop can’t work everywhere.

The aspect-ratio property, and when content wins

The aspect-ratio property gives a shape to any box, such as aspect-ratio: 16 / 9 on a video frame or a card. But it works only when at least one of the width and the height is automatic. auto 3 / 2 means “3:2 until the image’s own shape is known” (MDN, aspect-ratio).

Pause and predict: how tall is this box, in Chrome?

<div style="width: 120px; aspect-ratio: 1; border: 1px solid">Use a USB drive, a folder on your NAS, an SFTP server or any S3-compatible bucket. Switch any time.</div>
Answer

In one run in Chrome 157, it was 194 px tall, not 122. That’s because CSS Sizing Level 4 says such a box is at least as tall as its content, unless it’s an image or scrolls (CSS Sizing 4, §4.3). The text needs more than 120 px, so the box grows. Add overflow: auto, and the box stays 122 × 122 while the text scrolls; min-height: 0 also works.

So aspect-ratio is a preferred shape, and text can break it. That’s usually what you want, because a card that cut off its own text would be worse. aspect-ratio is Baseline widely available since 2024-03-20 (Chrome 88, Firefox 89, Safari 15). Before it, developers used an older technique with a percentage padding-top.

Two alternatives to an <img> with object-fit:

  • A CSS background with background-size: cover crops the same way, but the image isn’t in the HTML and has no alt text. WAI suggests CSS backgrounds for decorative images only (WAI, Decorative images).
  • object-view-box crops to a chosen rectangle of the image in CSS. It has limited availability: Chrome and Edge 104 and later only (web-features 3.46.0).

How the browser picks and loads an image file, with srcset, formats and lazy loading, is a performance topic. The site’s Debugging Web Performance course covers it in Module 3: The Slow First Load.

Rule: Never set both a width and a height on a photo with the default object-fit. Let the height follow the photo’s shape, or use object-fit: cover and pick the crop with object-position.

Text over a photo needs a scrim

Stashling keeps its text beside the photo, so this section is a try-out on a copy of the page, not a lab step. When a headline sits on a photo, contrast is what fails first.

Here’s the try-out. It wraps the photo in a figure and puts a white caption along its top edge:

<!-- excerpt: try-out, not part of the lab -->
<figure class="hero-photo">
  <img src="images/hero.webp" width="1200" height="800" alt="">
  <figcaption>Every file, every day, on a drive you own.</figcaption>
</figure>
/* excerpt: try-out, not part of the lab */
.hero-photo {
  position: relative;
  margin: 0;
}

.hero-photo figcaption {
  position: absolute;
  inset: 0 0 auto; /* a strip along the top edge of the photo */
  padding: var(--space-4) var(--space-5);
  color: var(--neutral-0);
  font-size: var(--step-2);
  font-weight: bold;
}

Pause and predict: which words of the caption in Figure 7 can you read, and which fail WCAG?

Figure 7: before. White text directly on the photo. Only the part over the laptop is readable.

Answer

Only “drive you own.” The letters over the laptop screen, #1e2a34, are 14.62:1. The rest fail: 1.38:1 over the sky, 1.29:1 over the wall, 1.12:1 over the sun, and 1.00:1 over the white window frame. We read these pixels from a headless Chrome screenshot and computed the ratios with the ratio function below.

WCAG 2.2 success criterion 1.4.3 asks for 4.5:1 for text and 3:1 for large text, as Module 6 taught. Text on a photo isn’t an exception, unless the text is part of a picture with other important content, or a logo (Understanding 1.4.3).

Failure F83 gives a quick check for text on a background image (F83). For light text, compare it with the lightest part of the image behind it. If that passes, every letter passes. If it doesn’t, you have to check the pixels next to each letter, as technique G18 describes (G18).

Photos change, and a crop moves the text, so the quick check is the one that holds.

How dark the scrim must be

A scrim is a semi-transparent layer between a photo and the text on it, dark under light text. The worst pixel under white text is white. So you need to know how dark a black layer must be for white text to pass on white.

This script answers it. It uses the WCAG 2 contrast formula from Module 6:

// scrim.mjs: run with `node scrim.mjs`
// WCAG 2 contrast of white text over a black scrim, on the brightest pixel a photo can have
const lin = (c) => ((c /= 255) <= 0.04045 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4);
const lum = ([r, g, b]) => 0.2126 * lin(r) + 0.7152 * lin(g) + 0.0722 * lin(b);
const ratio = (x, y) => (Math.max(lum(x), lum(y)) + 0.05) / (Math.min(lum(x), lum(y)) + 0.05);
const white = [255, 255, 255];
// Black at opacity a over a pixel, mixed the way browsers do by default (in sRGB)
const scrim = (px, a) => px.map((c) => Math.round(c * (1 - a)));

for (const a of [0, 0.4, 0.45, 0.5, 0.55, 0.6]) {
  const bg = scrim(white, a);
  console.log(`scrim ${a}: background rgb(${bg}), white text ${ratio(white, bg).toFixed(2)}:1`);
}
scrim 0: background rgb(255,255,255), white text 1.00:1
scrim 0.4: background rgb(153,153,153), white text 2.85:1
scrim 0.45: background rgb(140,140,140), white text 3.36:1
scrim 0.5: background rgb(128,128,128), white text 3.95:1
scrim 0.55: background rgb(115,115,115), white text 4.74:1
scrim 0.6: background rgb(102,102,102), white text 5.74:1

So a black scrim at 55% opacity is the lightest of these steps that gives white body text 4.5:1 on any photo. For large text, 45% gives 3:1. The script assumes that the browser mixes the layer with the pixel in sRGB, the CSS default. To check that, we read the pixel over the white window frame under the scrim in Chrome, and it was #737373, which is rgb(115 115 115), as computed.

The try-out adds one line to the caption:

/* excerpt: try-out, not part of the lab */
  background: rgb(0 0 0 / 0.55); /* the scrim */

Figure 8: after. A 55% black strip behind the caption. Every letter is at least 4.74:1.

The cost is the photo itself, because its colors under the strip are 55% darker. The caption here is 23 to 28 px bold, large-scale text, so 45% would pass today. But we keep 55%, so the strip still works if someone makes the text smaller.

The scrim depends on the photo, not on the theme. A white caption on a photo needs the same strip in the light and the dark theme, so it has no light-dark() value.

Four other ways to make text on a photo readable, with their costs:

Pattern What you do Cost
Text beside the photo Keep the text off the image, as Stashling does No contrast problem; the photo and text need their own space
Solid text box A panel of one color behind the text Readable on any photo; covers part of it
Gradient scrim Dark only where the text is, fading out Keeps more of the photo; the text area moves when the crop changes or the text wraps, so test at every width
Outline or halo text-shadow around each letter G18 accepts a dark outline of at least 1 px; thin shadows rarely cover every pixel, so use it with a scrim, not alone

A frosted panel with backdrop-filter: blur() is Baseline newly available since 2024-09-16, so give it a solid background color as a fallback.

Rule: For text over a photo, check the text against the lightest pixel the text can sit on, and add a scrim until that check passes.

A bright photo on a dark page

Module 6 made a dark theme and left this problem for this module. Figure 9 is the landing page in the dark theme after the crop.

Figure 9: before. In the dark theme, the photo is brighter than the text.

The page’s text is #e8e8e8, 12.98:1 on the surface #222222. But the photo’s wall is #e9e2d7, about as bright as the text, and its window frame is pure white. In Module 1, the element with the most contrast drew the eye first. Here that element is a mood image.

So the lab dims the photo when the reader’s system is set to dark:

/* excerpt from index.css */
/* In the dark theme, dim the photo so no part of it is brighter than the text */
@media (prefers-color-scheme: dark) {
  .hero img {
    filter: brightness(0.8);
  }
}

brightness() multiplies the picture’s colors: below 100% it darkens, 0% is black, and 100% leaves it unchanged (MDN, brightness()). The filter property is Baseline widely available since 2019-03-07.

Pause and predict: what color does the white window frame become at brightness(0.8)? And at 0.9?

Answer

#cccccb at 0.8, and #e5e5e5 at 0.9, from pixels read in Chrome 157. Chrome multiplies each sRGB channel: 255 × 0.8 = 204, which is cc. Both are darker than the text, #e8e8e8.

So 0.9 already meets the comment’s rule. But we chose 0.8 because the wall is a large area, and at 0.9 it stays #d2cbc1, close to the text. At 0.8 it’s #bab5ac. That’s our judgment; we didn’t find a study that gives a number.

Figure 10: after. At 80% brightness, the headline is brighter than any part of the photo.

The cost is detail in the dark parts. The laptop screen goes from #1e2a34 to #18222a, close to black, and every color in the photo is 20% darker in each channel.

The page’s dark theme comes from color-scheme: light dark, which follows the same system setting as the media query. That leaves one gap. Browsers without light-dark() (before Chrome 123, Firefox 120 and Safari 17.5) keep the light theme, but they still dim the photo when the system is dark.

The alternative is a second photo made for the dark theme, such as the same desk at night. <picture> with <source media="(prefers-color-scheme: dark)" srcset="hero-dark.webp"> serves it today. light-dark() with two images, light-dark(url(day.webp), url(night.webp)), is Baseline newly available since 2026-09-14 (Chrome 150, Firefox 150, Safari 27). The cost is a second file to make and keep in step with the first.

Rule: In a dark theme, no image should be brighter than the text; dim a mood image or give it a dark version.

Alt text depends on why the image is there

The photo’s alt text was “A laptop running Stashling on a desk next to an external drive”. That describes the picture. The question is whether it does a job for a reader who can’t see it.

A text alternative is text that does the job of an image, or other non-text content, for someone who can’t see it. In HTML it’s the alt attribute. WCAG 2.2 success criterion 1.1.1, at level A, asks that it “serves the equivalent purpose”, and that decoration is marked so assistive technology can ignore it (Understanding 1.1.1).

W3C’s alt decision tree asks these questions in order (WAI, An alt Decision Tree):

  1. Does the image contain text? If the same text is next to it, use alt="". Otherwise, put the text in the alt.
  2. Is it in a link or a button, and would the purpose be unclear without it? Describe where the link goes or what the button does.
  3. Does it add meaning? Describe the meaning of a simple image briefly, and give a chart’s information on the page. If it repeats nearby text, use alt="".
  4. Is it purely decorative? Use alt="".

Pause and predict: walk Stashling’s photo through the tree. What alt text does it get?

Answer

alt="". It has no text and isn’t in a link. It shows a computer that backs up to a drive, and the tagline right above it says “Back up your home folder to any storage you own.” So it repeats nearby text, and a screen reader user loses nothing without it.

The lab changes one attribute:

<!-- excerpt from index.html -->
<img src="images/hero.webp" width="1200" height="800" alt="">

That’s a design decision, because only the author knows why the image is there, and WAI says so. The same screenshot of a settings page can need a description in a tutorial step that only the picture explains. But next to a caption that says the same thing, it needs alt="".

Three failures in WCAG’s list are worth knowing. F38 is a decorative image that is not marked as one. F39 is a decorative image with an alt like “spacer”. F30 is a file name or placeholder as alt text, such as alt="image1.jpg".

Never leave the alt attribute out, because some screen readers then read the file name. WAI’s page, from 2019, also notes that role="presentation" has weaker support than alt="".

The cost of alt="" is that a screen reader user never learns the photo exists. That’s right for a mood image, but for an image that shows the product, it’s a loss. In this course, every figure’s alt text says what the reader should see, because each figure carries a lesson.

Rule: Write alt text for the image’s job on this page: the meaning it adds, the action it starts, or alt="" when the text already says it.

One icon set: one grid, one stroke, one size

Look at the four icons in Figure 1 again. Each one alone is a fine icon. But together they look accidental, because they follow four sets of rules.

An icon set is a collection of icons drawn to the same rules, so that any two look like they belong together. Lucide’s design guide lists those rules for its set (Lucide, Icon design guide). Every icon is drawn on a 24 × 24 canvas with a 2 px stroke and round line ends. It has at least 1 px of padding and a 2 px corner radius.

A stroke is the line that an outline icon is drawn with. Its width is set in the icon’s own units, so a stroke of 2 means 2 of the 24 units.

Three free sets, as their repositories were on 2026-11-18:

Set License Drawing rules Size of the set
Lucide ISC; icons taken from Feather are also MIT 24 × 24, 2 px stroke, round ends; one style about 2,000 icons
Heroicons MIT Outline: 24 × 24, 1.5 stroke. Solid: 24 × 24. Mini: 20 × 20. Micro: 16 × 16. The last three are filled about 300 icons per style
Phosphor MIT Six weights: Thin, Light, Regular, Bold, Fill, Duotone; drawn on a 16 px grid, exported at 256 units about 1,500 icons per weight

Mix two sets, and you mix their strokes. On the same 24 px grid, Lucide’s 2 px line next to Heroicons’ 1.5 px line is 2 / 1.5 = 1.33 times as heavy. That’s the difference you saw in Figure 1, only larger.

A stroke grows with the icon

The stroke is in the icon’s units, so it scales with the icon. Figure 11 shows one Lucide icon at three sizes.

Figure 11: one icon at three sizes. A 2-unit stroke is 1.33 px at 16 px and 2.67 px at 32 px.

The arithmetic is 2 × 16 / 24 = 1.33 and 2 × 32 / 24 = 2.67. So icons of one set at different sizes still look mixed. Heroicons answers this by drawing separate 20 px and 16 px sets instead of shrinking the 24 px one. In SVG, vector-effect: non-scaling-stroke keeps a stroke at the same screen width at any size; it’s part of SVG, which is Baseline widely available.

So Stashling draws every icon at one size, set as a token:

/* excerpt from tokens.css */
  /* Icons: one set, Lucide, drawn on a 24px grid with a 2px stroke */
  --icon-size: 1.5rem; /* 24px, the set's own grid, so every stroke draws 2px wide */
/* excerpt from index.css */
.feature svg {
  inline-size: var(--icon-size);
  block-size: var(--icon-size);
}

Pause and predict: a reader sets the browser’s default font size to 24 px. How large are the icons, and how wide are their lines?

Answer

1.5rem is 36 px, so each line is 2 × 36 / 24 = 3 px. The icons grow with the text, as rem did for the breakpoint in Module 7, and they all grow together, so they still match.

Each icon is Lucide’s SVG source, copied from its repository, with aria-hidden="true" added. Here’s the lock:

<!-- excerpt from index.html: the first feature card -->
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
  <rect width="18" height="11" x="3" y="11" rx="2" ry="2"/>
  <path d="M7 11V7a5 5 0 0 1 10 0v4"/>
</svg>

Notice three things:

  1. stroke="currentColor" draws the line in the text color, so the theme recolors the icon. The old cloud’s #0000ff was 1.85:1 on the dark page, from the same ratio function. currentColor is Baseline widely available.
  2. width and height in the HTML keep the icon at 24 px if the CSS doesn’t load. The CSS sets the size everyone sees.
  3. viewBox stays, because it’s what lets the icon scale. An SVG optimizer can remove it, and the icon then stops resizing with CSS.

Figures 12 and 13 show the feature cards in the dark theme before and after.

Figure 12: before. Four sizes, four line weights, and a blue cloud that disappears in the dark theme.

Figure 13: after. One set, one size, one line weight, in the text color. The titles start 24 px higher.

The titles moved because of Module 7’s subgrid: the icon row is as tall as the tallest icon, which was 48 px and is now 24 px.

A set has costs too. It has one style, and it may lack an icon you need. When it does, you draw the missing icon by the set’s own rules, or switch the whole site to a set that has it. Lucide is the lab’s set because three of the four old icons were outlines; Heroicons or Phosphor would work as well if every icon came from it.

SVG or an icon font

Phosphor’s simplest path for a plain web page is an icon font, which puts each icon in a private code point of a font. But Tyler Sticka argued against icon fonts in 2015 (Sticka, Cloud Four, 2015).

Screen readers may read the code points. Fonts that readers choose, such as fonts for dyslexia, can replace the icons, and a font that fails to load leaves empty boxes. His evidence is mostly argument and examples from 2015, and some readers disputed points. Inline SVG avoids all of these, so the lab uses it.

Rule: Take every icon from one set, draw them all at one size from a token, and color them with currentColor.

An icon needs a word next to it

An icon is a picture of a word, and readers don’t all read the same word from it. NN/g’s usability article found that only a few icons mean the same thing to almost everyone, such as home, print and search (Harley, NN/g, 2014). A heart or a star means different things on different sites.

So its advice is a visible text label at all times. A label that appears only on hover costs an extra step and doesn’t work on touch screens. But the evidence is examples from NN/g’s studies, without participant numbers, so treat it as expert advice.

The strongest numbers are about the menu icon. In NN/g’s 2016 test with 179 users on phones, 89% used the navigation on a site that showed part of it on the page. On a site that hid every link behind a menu icon, 44% did (Pernice and Budiu, NN/g, 2016).

NN/g’s 2025 article found that most participants now recognize the three-line menu icon, mostly when it’s at the top left. But it still advises a “Menu” label for less experienced users (Kaplan, NN/g, 2025).

A functional image is an image that starts an action or goes somewhere, such as an icon inside a link or a button. WAI says its text alternative names the action, “Search”, not the picture, “magnifying glass” (WAI, Functional images). When visible text next to the icon already says the same, the icon gets alt="", so a screen reader doesn’t say it twice. For inline SVG, aria-hidden="true" does the same job; the WAI page covers <img>, and Heroicons ships its SVGs with that attribute.

On Stashling, each feature icon sits above its title, and the title says what the icon means. So the icons are decorative, and each has aria-hidden="true".

Pause and predict: the gear at the right of the header is a link to the settings page, with aria-label="Settings" and no text. Does it follow this section’s advice?

Answer

Half of it. A screen reader says “Settings”, because the link has a name that names the destination. But a sighted visitor sees only a gear, with no word next to it. The gear isn’t one of the few icons that NN/g found everyone reads the same way.

The lab redraws the gear with Lucide’s settings icon at the same token size, so the header matches the cards. But it doesn’t add the label. That’s because where Settings belongs in the navigation, and what it’s called there, is the problem that Module 11, Usability: Conventions, Navigation and Quick Tests, starts from.

Rule: Put a visible word next to every icon that is not home, print or search, and hide the icon from screen readers when the word is already there.

Images and icons: choices and costs

Decision Choice in the lab Cost or limit Choose something else when
Keep a photo? Keep the mood photo, below the main action Space and attention for no information It pushes the main action down, or it is generic: no image
Photo shape height: auto from the attributes, max-block-size: 20rem The crop changes with the width The focal point must be framed differently on a phone: art direction with <picture>
Fill the box object-fit: cover Edges of the photo are lost Nothing may be cut, such as a logo or a screenshot: contain
The crop object-position: 50% 63% Right at 1280; shows part of the clock at 900 The subject sits elsewhere in the photo: another position
Text on a photo None; text beside the photo — You must put text on it: a 55% scrim (4.74:1) or a solid text box
Photo in the dark theme filter: brightness(0.8) Dark detail and some color are lost The photo matters: a dark version with <picture> or light-dark()
Alt text alt="" A screen reader user never learns the photo exists The image shows the product or explains a step: describe its meaning
Icons One set, Lucide, inline SVG, currentColor One style; a missing icon must be drawn to its rules A designer gives you a set: use it for every icon
Icon size One token, --icon-size: 1.5rem Every icon is 24 px, even beside small text An icon sits inside a line of text: size it in em or lh

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.

  • aspect-ratio, and the mapping from <img width height> to it, became Baseline widely available on 2024-03-20. Safari 15 was the last to ship them, in 2021.
  • image-set(), the CSS version of srcset for background images, became widely available on 2026-03-18.
  • The lh unit, one line of the element’s text, became widely available on 2026-05-21. It sizes an icon to the line it sits in: block-size: 1lh.
  • CSS masks (mask-image) became widely available on 2026-06-07.
  • light-dark() with images became newly available on 2026-09-14.
  • backdrop-filter is newly available since 2024-09-16. object-view-box is still limited to Chrome and Edge.
  • SVGO 4, the optimizer behind SVGOMG, stopped removing viewBox and <title> by default in June 2025, to keep scaling and accessible names (SVGO, Migration from v3 to v4).

object-fit, object-position, <picture>, filter, gradients, text-shadow, currentColor and inline SVG have all been widely available for years.

Online tools for this step

All three were checked on 2026-11-18. The icon sets are compared in “One icon set: one grid, one stroke, one size”.

  • Unsplash. A free photo library under the Unsplash License: you may use, change and share the photos, for commercial work too, with no attribution needed. You may not sell photos without changing them significantly, or copy the library into a competing service.

Limit: its terms say the license gives no rights to trademarks, recognizable people or works of art in a photo, so you may need their permission. Unsplash+ photos use a separate paid license. DevTools has no equivalent.

  • Pexels. A free library of photos and videos under the Pexels License: free use, attribution optional, changes allowed.

Limit: you may not show identifiable people in a bad light, suggest that people or brands endorse you, sell unchanged copies, or use a photo in a trademark. Neither license is a Creative Commons license. Photos from both sites appear on many other sites, which is the stock-photo cost from “Every image needs a job”.

  • SVGOMG. A web page for SVGO 4: paste an SVG, see it smaller, and turn each optimization on or off. Limit: one file at a time, and its “Remove viewBox” option stops an icon from scaling if you turn it on. It is MIT licensed. DevTools can show and edit SVG markup in the Elements panel, but it doesn’t make it smaller.

Check yourself

Critique: the landing page with a team photo

A startup’s landing page opens with a photo from a free library: five people high-fiving in a bright office with large white windows. The headline, “Ship faster together”, is white text on the windows, which are about #f0f0f0. Below it, a toolbar has three buttons with only icons: a pencil, a trash can and a star that means “pin to top”. Their names appear only on hover.

Further down, a screenshot of the product has alt="image1.jpg", and no other text on the page explains what it shows.

Hint 1

Which job from the four does the team photo do? What does NN/g say about photos like it, and what does the library’s license not cover?

Hint 2

Use F83’s quick check on the headline. How dark must a scrim be?

Hint 3

Which icons does NN/g name as understood by almost everyone? What do the toolbar buttons need for a sighted user, and for a screen reader user?

Answer
  1. The team photo is a stock photo that sets a mood, so readers tend to skip it (NN/g 2010). It shows recognizable people, and the free licenses give no rights to them, so the page may need their permission. A real screenshot of the product would do a job.
  2. White on #f0f0f0 is 1.14:1, computed with the module’s ratio function. So a 55% black scrim behind the headline makes it at least 4.74:1 on any pixel; if the headline is large-scale text, 45% gives the 3:1 it needs. Moving the headline off the photo also works.
  3. Pencil, trash and star aren’t among the few icons everyone reads the same way. A star for “pin” is this site’s own meaning, and hover-only names fail on touch screens. So give each button a visible word, “Edit”, “Delete”, “Pin”, and hide the icon from screen readers. Without visible words, the buttons need names that say the action.
  4. alt="image1.jpg" is failure F30. The screenshot is the only explanation of what it shows, so its alt text must describe that, such as “The dashboard with the deploy history of three projects”.

Review questions

  1. What does object-fit: fill do, and why is it the value behind most squeezed photos?
  2. A box with aspect-ratio: 16 / 9 holds a long paragraph and is taller than 16:9. Why, and what keeps it at 16:9?
  3. How dark must a black scrim be for white body text on any photo, and why is the answer the same in the light and the dark theme?
  4. The same screenshot appears in a tutorial step that only the picture explains, and in a gallery next to a caption that says the same. What alt text does each get?
  5. A Lucide icon is drawn at 16 px next to a Heroicons outline icon at 24 px. How wide is each one’s line, and which two changes make the icons match?
Answers
  1. It stretches the picture to the box’s width and height, and it’s the initial value. So a width and a height that don’t match the photo’s aspect ratio distort it, unless you change object-fit.
  2. A box with an aspect ratio that doesn’t scroll is at least as tall as its content. overflow: auto or min-height: 0 keeps the ratio, and the text then scrolls inside the box.
  3. 55% black gives 4.74:1 on white, the worst pixel. It depends on the photo’s pixels, not on the page’s colors, so the theme doesn’t change it.
  4. In the tutorial, a short description of what the picture shows for that step. In the gallery, alt="", because the caption already says it.
  5. Lucide’s 2-unit stroke at 16 px is 2 × 16 / 24 = 1.33 px; Heroicons’ 1.5 stroke at 24 px is 1.5 px. Take both icons from one set, so they share one stroke rule, and draw both at one size from one token, so the stroke draws at one width.

The lab: a photo that keeps its shape and icons from one set

In about 15 minutes, you crop the photo instead of squeezing it, decide its alt text and dim it in the dark theme. Then you replace every icon on the site with Lucide icons at one size. Start from the module-07 folder and reload after each step. The finished files are in the module-08 folder of the course repository, with Lucide’s license in icons/LICENSE.

Step 1: crop the photo instead of squeezing it

Why: a fixed height on an image distorts it (see “object-fit keeps a photo’s shape”).

In index.html, add the photo’s size to the <img> in the hero:

<img src="images/hero.webp" width="1200" height="800" alt="A laptop running Stashling on a desk next to an external drive">

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

.hero img {
  width: 100%;
  height: auto;             /* the photo's own 3:2 shape, from its width and height attributes */
  max-block-size: 20rem;    /* never taller than 320px, so a wide screen gets a band */
  object-fit: cover;        /* fill the box and crop what does not fit; never squeeze */
  object-position: 50% 63%; /* keep the laptop and the drive inside the band */
}

What you should see: Figure 4 instead of Figure 3 at 1280 px, and Figure 6 instead of Figure 5 at 390 px. In device mode, drag the width from 390 to 1280. The photo stays whole up to a 512 px window, then becomes a band that crops.

Step 2: decide the alt text

Why: the photo repeats the tagline, so it adds nothing for a screen reader user (see “Alt text depends on why the image is there”).

In index.html, change the photo’s alt text:

<img src="images/hero.webp" width="1200" height="800" alt="">

What you should see: no change on screen. A screen reader now skips the photo.

Step 3: dim the photo in the dark theme

Why: in the dark theme, the photo was brighter than the text (see “A bright photo on a dark page”).

In index.css, add this rule after the .hero img rule:

/* In the dark theme, dim the photo so no part of it is brighter than the text */
@media (prefers-color-scheme: dark) {
  .hero img {
    filter: brightness(0.8);
  }
}

What you should see: in DevTools, open the Rendering tab and set “Emulate CSS media feature prefers-color-scheme” to dark. Figure 10 instead of Figure 9. With light, the photo is unchanged.

Step 4: add the icon size token

Why: every icon draws at one size, from one place (see “A stroke grows with the icon”).

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

  /* Icons: one set, Lucide, drawn on a 24px grid with a 2px stroke */
  --icon-size: 1.5rem; /* 24px, the set's own grid, so every stroke draws 2px wide */

What you should see: no change yet.

Step 5: replace the four feature icons

Why: the four icons came from four sets (see “One icon set: one grid, one stroke, one size”).

In index.html, replace each <svg> in the four .feature cards with the Lucide icon below, in this order: lock, layers, zap and cloud. Each is the SVG from Lucide’s icons/ folder, with aria-hidden="true" added.

<!-- excerpt from index.html: the svg at the top of each .feature card -->
          <svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
            <rect width="18" height="11" x="3" y="11" rx="2" ry="2"/>
            <path d="M7 11V7a5 5 0 0 1 10 0v4"/>
          </svg>

          <svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
            <path d="M12.83 2.18a2 2 0 0 0-1.66 0L2.6 6.08a1 1 0 0 0 0 1.83l8.58 3.91a2 2 0 0 0 1.66 0l8.58-3.9a1 1 0 0 0 0-1.83z"/>
            <path d="M2 12a1 1 0 0 0 .58.91l8.6 3.91a2 2 0 0 0 1.65 0l8.58-3.9A1 1 0 0 0 22 12"/>
            <path d="M2 17a1 1 0 0 0 .58.91l8.6 3.91a2 2 0 0 0 1.65 0l8.58-3.9A1 1 0 0 0 22 17"/>
          </svg>

          <svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
            <path d="M15.914 4a1.5 1.5 0 00-2.474-1.561l-9 9A1.5 1.5 0 005.5 14h4.002a.5.5 0 01.471.666L8.086 20a1.5 1.5 0 002.475 1.56l9-9A1.5 1.5 0 0018.5 10h-3.997a.5.5 0 01-.472-.667z"/>
          </svg>

          <svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
            <path d="M17.5 19H9a7 7 0 1 1 6.71-9h1.79a4.5 4.5 0 1 1 0 9Z"/>
          </svg>

In index.css, add this rule after the .feature h3, .feature p rule:

.feature svg {
  inline-size: var(--icon-size);
  block-size: var(--icon-size);
}

What you should see: Figure 13 instead of Figure 12, in the dark theme at 1280 px. In the light theme, the four icons are the text’s dark gray.

Step 6: redraw the gear in the header

Why: the header’s gear is the last icon from another set (see “An icon needs a word next to it”).

In all four HTML files, replace the <svg> inside the .settings-link link with Lucide’s settings icon:

<!-- excerpt: the same lines in index.html, article.html, signup.html and settings.html -->
      <svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
        <path d="M9.671 4.136a2.34 2.34 0 0 1 4.659 0 2.34 2.34 0 0 0 3.319 1.915 2.34 2.34 0 0 1 2.33 4.033 2.34 2.34 0 0 0 0 3.831 2.34 2.34 0 0 1-2.33 4.033 2.34 2.34 0 0 0-3.319 1.915 2.34 2.34 0 0 1-4.659 0 2.34 2.34 0 0 0-3.32-1.915 2.34 2.34 0 0 1-2.33-4.033 2.34 2.34 0 0 0 0-3.831A2.34 2.34 0 0 1 6.35 6.051a2.34 2.34 0 0 0 3.319-1.915"/>
        <circle cx="12" cy="12" r="3"/>
      </svg>

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

.settings-link svg {
  inline-size: var(--icon-size);
  block-size: var(--icon-size);
  vertical-align: middle;
}

What you should see: a 24 px gear with a 2 px line at the right of the header, instead of a 14 px one. The header stays 54 px tall at 1280.

Step 7: check both themes, both widths and the icon sizes

Why: a crop and a filter are easy to get right at one width and in one theme only.

On index.html, run this in the console:

[...document.querySelectorAll("svg")].map((svg) => svg.getBoundingClientRect().width)

Then look at the page at 390 and 1280 px, in the light and the dark theme.

What you should see: the console prints [24, 24, 24, 24, 24], the gear and the four feature icons. At 1280 in the light theme, the page looks like Figure 14, in the same crop as Figure 1.

At 390, the whole photo shows, with a round clock. In the dark theme, the photo is dimmed and the icons take the light text color. At 320 px, document.documentElement.scrollWidth is still 320 on all four pages.

Figure 14: after the lab, in the same crop as Figure 1. The photo keeps its shape, and the icons come from one set.

Optional: apply it to a page of your own

Pick a page of your own with images or icons.

  1. Write down the job of each image. Cut each mood image that pushes the main action down.
  2. Search your CSS for images with both a width and a height. Give each one height: auto, or object-fit: cover and an object-position that keeps its focal point.
  3. Run each image through the alt decision tree, and fix every alt that names a file or describes a picture nobody needs.
  4. List your icons by source, size and line weight. Move all of them to one set and one size token.

Then look at the page in the dark theme, and find anything brighter than the text.

Module 8 cheat sheet

Job        show the thing, show the people, explain, or set a mood (cut first)
Shape      <img width height> + height: auto; never a free width and height
Fill       object-fit: cover crops; fill (the default) squeezes; contain bars
Crop       object-position: x% y% keeps the focal point; test several widths
Text       check the lightest pixel; black scrim 0.55 = 4.74:1 on white
Dark       no image brighter than the text: filter: brightness(0.8)
Alt        the job on this page; alt="" when nearby text says it
Icons      one set, --icon-size: 1.5rem, stroke="currentColor", keep viewBox
Labels     a visible word beside every icon but home, print and search

Module 9, Components, States and Motion, starts with a disabled button that looks enabled and a link nobody sees.

Sources

Standards and W3C guidance:

CSS references:

Research, cited with the strength of its evidence:

Icon sets and licenses:

Browsers:

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

The measured numbers in this module, such as box sizes, crop rows and pixel colors, come from runs of the lab pages in headless Chrome 157 on macOS. The default font size was 16 px. Pixel colors were read with the sRGB color profile forced. Your numbers will differ if you use other browsers or settings.