Sub topic 3
Checking quality and resolution
This chapter assumes you know the img element and its attributes, basic CSS sizing, and how breakpoints work in a responsive layout. Before you crop or style a photo, confirm that the file can survive the sizes where you will show it.
Resolution is relative to display size
A photo's resolution is its pixel dimensions, such as 1600 × 900. Whether that is enough depends on how large the photo appears and on the screen's pixel density.
A screen with a device pixel ratio (DPR) of 2 uses a 2 × 2 block of physical pixels for each CSS pixel. An image shown at 600 CSS pixels wide needs about 1200 pixels of width to look sharp on that screen.
The rule of thumb is this:
- Find the largest width, in CSS pixels, at which the image will display.
- Multiply by 2 to cover high-density screens.
- Compare the result to the file's real width.
| Slot on the page | Display width | Minimum source width (at 2x) |
|---|---|---|
| Avatar | 80px | 160px |
| Card thumbnail | 360px | 720px |
| Half-width photo | 600px | 1200px |
| Full-width hero (1440px max) | 1440px | 2880px |
If the source is smaller than the target, the browser stretches it. Upscaled photos look soft or blocky, and no CSS property repairs that.
Crop before you measure
Cropping removes pixels. A 4000 × 3000 photo that you crop to a tight 1000 × 750 region is now a 1000-pixel photo. Always measure the resolution of the crop you plan to use, not the original file.
Resolution is not the same as quality
A large file can still be a poor photo. Zoom to 100% and look for these problems:
- Blur. Motion blur or missed focus on the subject. Soft backgrounds are fine, but the subject should be sharp.
- Noise. Grainy speckles, common in low-light shots. Noise gets worse when you sharpen or compress.
- Compression artifacts. Blocky patches or halos around edges, often from a photo that was saved as JPEG several times.
- Exposure. Faces lost in shadow, or bright areas that have turned pure white.
- Color cast. A yellow or blue tint that makes skin or products look wrong.
- Watermarks and stamps. Date stamps or stock-site marks that appear in the pixels.
A quick check is to view the image at the exact size it will have on the page, then at 200%. If it holds up at 200%, it will hold up on high-density screens.
Read the file's real dimensions
Do not trust the size a file appears to have in a page or an email. Check the file itself. In the browser's developer tools, an img element exposes both values:
<img id="photo" src="team-800.jpg" alt="Four colleagues around a whiteboard">
<script>
const img = document.getElementById("photo");
img.addEventListener("load", () => {
console.log("Natural size:", img.naturalWidth, "x", img.naturalHeight);
console.log("Displayed size:", img.clientWidth, "x", img.clientHeight);
console.log("Device pixel ratio:", window.devicePixelRatio);
});
</script>If naturalWidth is lower than clientWidth * devicePixelRatio, the browser is upscaling the image.
Common mistakes
- Judging sharpness on a small preview instead of at 100%.
- Taking a screenshot or a social media download as the "original". These are usually small and heavily compressed.
- Upscaling a small file in an editor and assuming the detail is real.
- Checking only the desktop slot and forgetting that a mobile layout may crop tighter.
Exercise
A designer plans a half-width photo that displays at 640 CSS pixels wide. The designer has a 1000 × 750 file, and the crop removes the left 200 pixels of width. Is the crop sharp enough for 2x screens? What would you do?
Show answer
The crop is 800 pixels wide, but 2x screens need about 1280 pixels (640 × 2). The browser would upscale it, so it will look soft. Ask for a larger original, choose a looser crop that keeps more pixels, or reduce the display width to about 400 CSS pixels.