To resize images for the web without losing quality, scale down from the original file to the exact pixel dimensions your layout needs, accounting for the display's pixel density. Avoid upscaling: enlarging a low-resolution image adds file weight without recreating missing detail. Keep a master copy, resize proportionally, and verify the delivered file at its actual display size.
Why should you avoid upscaling images?
Enlarging a source image beyond its native pixel dimensions does not add real detail. Resizing software interpolates new pixels from the ones that already exist, which can soften edges or introduce visible artifacts on fine lines and text. Upscaling a low-resolution image increases file size without improving visual quality, because the process cannot recreate information that was never captured by the original file.
How to resize images for the web without losing quality
A file has intrinsic pixel dimensions that are separate from the size CSS renders it at. A display with a higher pixel ratio may need more source pixels than the CSS size implies, so a strict one-to-one match between file pixels and CSS pixels is not always the goal. Decide the largest CSS width the image will ever render at on your page, multiply by the highest density you intend to support, and resize the source to that pixel count.
Illustrative example: a 3000 by 2000 source resized to a 1200-pixel long side becomes 1200 by 800, preserving the original 3:2 ratio. Fitting that same source inside a 1000 by 1000 box produces roughly 1000 by 667, not a square. If a destination genuinely needs a square image, decide in advance between cropping the subject or adding canvas space. Typing equal width and height into a fit control does not choose the framing for you.
A DPI value stored in a file's metadata does not define how large the image appears on screen or how much detail a browser renders. Only the pixel dimensions and the CSS applied to the element determine the rendered size on the web.
When to use srcset and sizes for responsive delivery
For responsive layouts, export a small set of width variants, for example 480, 800, 1200 and 1600 pixels, and let the browser choose between them. The srcset attribute lets you list several image files so the browser can pick the most appropriate one for the current viewport and device pixel ratio, rather than always downloading the largest file.
The sizes attribute tells the browser how wide the image will render in the layout, which it needs to know before layout happens in order to pick correctly from srcset. Get this value wrong, for example leaving the default full viewport width when the image actually renders at half that width, and the browser will select an oversized candidate.
If an image always displays at a fixed CSS size regardless of viewport, you can skip sizes and use density descriptors instead, such as listing a standard file at 1x and a double-resolution file at 2x, letting the browser choose based on pixel density alone.
How to reserve layout space with width and height attributes
Set width and height attributes, or an equivalent aspect-ratio rule in CSS, on every img element so the browser can allocate space before the file finishes downloading. Specifying width and height attributes reserves the correct space in the layout, which helps minimize Cumulative Layout Shift because the browser does not need to wait for the image to load to know how much room it occupies.
Reserving space is about layout stability, not file weight. A correctly sized image with no dimension attributes can still cause a shift as it loads, and a lightweight file reserved with the wrong aspect ratio can still push surrounding content around once it appears.
Which resizing approach fits your scenario?
| Scenario | Recommended approach |
|---|---|
| Image renders at one fixed CSS size on every device | Density descriptors (1x, 2x) in srcset |
| Image renders at different widths depending on viewport | Width-based srcset plus an accurate sizes value |
| Source needs a different aspect ratio than the destination | Decide crop versus added canvas before export, not an automatic fit |
| Source is already below the target pixel dimensions | Keep it as is; do not upscale |
How to inspect image quality after resizing
Compare the resized export against the original at 100 percent and again at the actual delivery size on the page. Look closely at text, hair, product labels and diagonal lines, where resampling artifacts show up first. Apply any sharpening conservatively; it cannot restore detail that downscaling removed, and heavy sharpening introduces visible halos around edges instead.
- →Confirm the exported file's pixel dimensions match the layout or the relevant srcset entry.
- →Open the live page and inspect the actual image request in browser devtools, not just the export folder.
- →Zoom to 100 percent on a few high-detail regions, such as text or fine lines, and compare with the original.
- →Confirm density descriptors or sizes values match the rendered CSS width rather than a guess.
Two limitations are worth noting. Browser decoding and rendering behavior varies across browsers and devices, so the same file can look slightly different depending on where it is viewed; that is rendering variance, not a defect in the export. And if the destination format is lossy, such as JPEG, some detail loss is inherent even at high quality settings, so a visually acceptable result is not the same as a pixel-identical copy of the source.
Next step: pick one page, identify the largest rendered width of its main image at your most common viewport, resize a copy to that width without upscaling, add the correct srcset, sizes, width and height attributes, then load the live page and compare the served file at 100 percent zoom against the original before replacing it.