Sub topic 9
Images, icons and asset quality
This chapter assumes you can open DevTools, read the Elements and Computed panes, and know basic HTML and CSS (the box model, img, srcset, object-fit). It covers the last measurement pass on a built page: whether images, icons and other assets are the right size, sharp, correctly cropped and correctly colored.
What to check
Asset problems often look fine at a glance. A slightly soft logo or a stretched photo is easy to miss until you compare it with the design. Work through these checks for each asset.
- Sharpness. The image's intrinsic size should be at least as large as the size it is displayed at, multiplied by the device pixel ratio (DPR). A 300 px wide slot on a 2x display needs about 600 px of image data.
- Aspect ratio. The image should not look squashed or stretched.
- Cropping. The visible part of the image should match the design's focal point.
- Format and weight. Icons and logos should be vector (SVG) where possible. Photos should be compressed and not far larger than needed.
- Color. An icon should use the color from the design, including in its hover and disabled states.
- Alt text. Meaningful images need a text alternative. Decorative ones need an empty
alt="".
Measuring an image in DevTools
Select the image in the Elements pane and hover over it. DevTools shows the rendered size and the intrinsic size. You can also read both from the console:
const img = document.querySelector('img');
console.log({
rendered: `${img.clientWidth}x${img.clientHeight}`,
intrinsic: `${img.naturalWidth}x${img.naturalHeight}`,
dpr: window.devicePixelRatio,
currentSrc: img.currentSrc,
needsAtLeast: Math.ceil(img.clientWidth * window.devicePixelRatio)
});If naturalWidth is smaller than needsAtLeast, the image will look soft. If the intrinsic ratio differs from the rendered ratio and object-fit is not set, the image is distorted. Check currentSrc to confirm the browser chose the file you expected from srcset. Repeat the check at each breakpoint, because a different file may load.
flowchart TDThe diagram below summarizes the decision for one image.
Icons
Zoom the browser to 400% and look at the icons. SVG icons stay crisp. Blurry edges mean a raster file (PNG or JPG) is in use. Then check:
- The icon's box size matches the design, and the glyph is centered in it.
- The icon is vertically aligned with adjacent text.
- The color follows the design. An SVG that uses
fill="currentColor"inherits the text color, which keeps hover states in sync. - The stroke width matches the other icons in the set.
Missing and broken assets
Check the Console and Network panels for 404 errors on images. Also look for assets that load but are the wrong ones: a placeholder left in, an old logo, or an icon from a different set. Compare each asset by eye against the design file.
Exercise
An avatar is displayed at 120 px wide on a page viewed at DPR 2. DevTools reports naturalWidth 150. Is the image the right size, and what would you report?
Show answer
No. The image needs at least 120 x 2 = 240 px of width to look sharp at DPR 2, and the file is only 150 px wide. It will look soft. Report that the avatar source is too small for 2x displays and ask for an export of at least 240 px wide, or a srcset that includes one.