Sub topic 3
Checking quality and resolution
This chapter assumes you know the img element, basic CSS sizing, and what a breakpoint is. It covers how to judge whether a photo is good enough technically before you commit to it. Later chapters cover cropping and delivering the right file sizes.
Why check quality before anything else
A photo can have the right subject and still fail on the page. It may look soft on a large display, show blocky artifacts, or be too small to fill its slot. Cropping makes this worse, because a crop throws away pixels. Check quality first, so you know how much room you have to crop later.
Quality has four parts:
- Resolution: how many pixels the file has.
- Sharpness: whether edges and detail are crisp where they matter.
- Exposure and color: whether highlights, shadows, and skin tones are usable.
- Compression damage: whether earlier saves left artifacts.
Pixels, not inches
Resolution on the web means pixel dimensions, such as 3000 × 2000. A pixel is one dot of color. The "dpi" or "ppi" metadata inside a file does not matter for screens. A 3000 × 2000 image tagged 72 dpi and the same image tagged 300 dpi look identical in a browser.
What matters is the relationship between the file's pixels and the pixels the browser needs to paint.
- CSS pixel: the unit you use in CSS. A slot that is
600pxwide is 600 CSS pixels wide. - Device pixel ratio (DPR): how many physical screen pixels make up one CSS pixel. Many phones and laptops have a DPR of 2 or 3.
The pixels you need are the slot width multiplied by the DPR:
needed width = displayed CSS width × device pixel ratioA 600px-wide slot on a DPR 2 screen needs 1200 pixels of image width to look sharp. A full-width hero on a 1440px viewport at DPR 2 needs 2880 pixels.
Work out the target size for each slot
Before you pick a photo, list where it will appear and how wide that slot gets at its largest. Then decide what DPR you want to support. DPR 2 is a common target. DPR 3 gives diminishing returns for photos, because the eye can rarely tell the difference and the files get much larger.
| Slot | Max CSS width | Target at DPR 2 |
|---|---|---|
| Full-width hero | 1600px | 3200px |
| Card thumbnail | 400px | 800px |
| Half-width feature image | 720px | 1440px |
| Avatar | 96px | 192px |
Treat the right-hand column as the minimum source width. You can serve smaller files to smaller screens (a later chapter covers srcset), but the original has to be at least as large as the biggest version you will serve.
Account for the crop
Resolution is measured after cropping, not before. If you plan to use only the right half of a photo, the usable width is half the file width.
You can compute it in a few lines:
def usable_width(file_width, crop_fraction):
"""Width in pixels left after cropping to a fraction of the width."""
return int(file_width * crop_fraction)
def is_big_enough(file_width, crop_fraction, slot_css_width, dpr=2):
return usable_width(file_width, crop_fraction) >= slot_css_width * dpr
# A 3000px-wide photo, cropping to 50% of its width, in a 720px slot at DPR 2
print(usable_width(3000, 0.5)) # 1500
print(is_big_enough(3000, 0.5, 720)) # True (needs 1440)
print(is_big_enough(2000, 0.5, 720)) # False (1000 < 1440)The same photo passes or fails depending on how tight the crop is. A wide landscape that is fine as a full-frame hero may fall short once you crop in on one person.
Upscaling does not add detail
If a photo is too small, enlarging it only spreads the existing pixels over a bigger area. The result looks soft or blurry. Browsers do this automatically when you stretch a small image with CSS, and "AI upscaling" tools can only guess at new detail. Guessing can invent odd textures on faces and text.
Rules of thumb:
- Never rely on CSS to enlarge a small image beyond its natural size on a hero or other prominent slot.
- A modest enlargement (up to about 10–20%) on a background or low-focus image is often acceptable.
- If the only available photo is too small, use it at a smaller size, such as a card instead of a hero, or pick another photo.
Check sharpness at 100%
Pixel dimensions say nothing about focus. A large photo can still be blurry from camera shake, a missed focus point, or heavy noise reduction.
To check sharpness:
- Open the image at 100% zoom, where one image pixel equals one screen pixel.
- Look at the subject, usually the eyes in a portrait or the main object's edges. This is where focus should be.
- Compare against the final display size. Slight softness that disappears when the image is shrunk to 600px is usually fine. Softness that is obvious at the final size is not.
Shallow depth of field (a blurred background) is a style choice, not a defect. The test is whether the intended subject is sharp.
Look for compression artifacts
JPEG compression discards detail to save space. Each time a lossy file is edited and saved again, the damage accumulates. Signs of it:
- Blocky 8 × 8 squares in smooth areas such as sky.
- Fuzzy "mosquito noise" around hard edges and text.
- Banding, where a smooth gradient turns into visible stripes.
- Color blotches on skin.
Use the original or the highest-quality version you can get. Do not take a photo from a social media post or a screenshot, because those have usually been recompressed and resized. Compress only once, at the end, when you export the version for the site. The formats chapter covers how.
Exposure, noise, and color
Check these quickly before moving on:
- Blown highlights: areas of pure white with no detail, such as a washed-out sky. They cannot be recovered and look harsh behind text.
- Crushed shadows: pure black areas with no detail.
- Noise: grainy speckle, common in low-light shots. It is more visible on large displays and also makes files bigger when compressed.
- Color cast: an orange or green tint from indoor lighting. A white or gray object in the frame is a handy reference.
- Consistency: photos in the same row or gallery should have similar brightness and color temperature, or the page looks patchy.
Small exposure and white-balance problems can be fixed in an editor. Blown highlights and heavy noise usually cannot.
Inspect the real file in the browser
You can verify what you are actually serving. The browser exposes both the file's natural size and the size it is rendered at:
// Run in the browser console on a page with images
document.querySelectorAll("img").forEach((img) => {
const dpr = window.devicePixelRatio;
const neededWidth = Math.round(img.clientWidth * dpr);
const status = img.naturalWidth >= neededWidth ? "ok" : "too small";
console.log(
img.currentSrc,
`natural: ${img.naturalWidth}px`,
`needed: ${neededWidth}px`,
status
);
});naturalWidth is the width of the file the browser loaded, and currentSrc is the file it chose. If naturalWidth is lower than the needed width, the image is being upscaled on that screen. If it is far higher, you are sending more data than the screen can use. Both are worth fixing, the second for performance.
Note that images that have not finished loading report naturalWidth as 0, so run the check after the page has loaded.
Common errors
- Trusting dpi metadata. It does not affect web display. Check pixel dimensions.
- Measuring before the crop. A large file can become a small one after you crop to the subject.
- Forgetting high-DPR screens. An image that looks fine on your desktop monitor looks soft on a phone or laptop with DPR 2.
- Using a recompressed copy. Screenshots and downloaded social media images already carry artifacts.
- Judging sharpness at thumbnail size. Check at 100% on the subject, then at the final size.
- Shipping the camera original. A 6000px, 8 MB file in a 400px card is wasteful. You need enough pixels, not the maximum number of them.
A quick decision flow
Summary
Work out the pixels each slot needs (CSS width × DPR), measure resolution after the planned crop, and check sharpness at 100% on the subject. Then look for compression artifacts, blown highlights, and noise. Use the browser console to confirm what is delivered. Photos that pass these checks are ready for the licensing and composition checks in the next chapters.
Exercise
A card on your page displays an image at 480 CSS pixels wide. You want it sharp on DPR 2 screens, and you plan to crop the photo to the central 60% of its width. What is the minimum width in pixels of the original file?
Show answer
The card needs 480 × 2 = 960 pixels after cropping. Since the crop keeps 60% of the width, the original must be at least 960 ÷ 0.6 = 1600 pixels wide.
Exercise
A teammate says a downloaded photo is fine for the hero because its metadata says 300 dpi. Why is that not enough, and what two checks would you do instead?
Show answer
The dpi value is only a print hint and has no effect in a browser. Instead, check the pixel dimensions against the slot's needed width (CSS width × DPR, after cropping), and inspect the photo at 100% zoom to confirm the subject is sharp and free of compression artifacts.