Image resizing and compression: the short answer
Resizing changes an image's pixel dimensions.[4] Compression changes how its image data is encoded.[1] For a smaller web image, first choose dimensions that suit its displayed size, then compare formats and compression settings while checking the result visually.[1][4] Keep the original: enlarging a small image cannot restore detail that was not captured, and lossy exports discard information.[1][4]
A browser-based resizer can prepare a copy locally for a one-off task. For a production website, also plan responsive variants, fallbacks, and delivery; one compressed image is rarely the right size for every screen.[3][4]
What resizing changes
A 2,000 × 1,500 pixel image contains more pixels than an 800 × 600 version.[4] Reducing dimensions removes samples; enlarging interpolates existing pixels and may look soft, but does not recover missing detail.[4] Preserve the aspect ratio unless you intentionally want to crop or stretch the picture.[4]
Choose dimensions from the rendered layout, not from a vague rule such as “always resize for mobile.” Device pixel ratio matters too: a display area of 500 CSS pixels may benefit from a larger source on a high-density screen.[4] For a responsive page, provide candidates with srcset and describe the expected rendered width with sizes, so the browser can choose an appropriate file.[4]
What compression changes
Compression encodes pixel information to reduce the stored file size.[1] Lossless compression can reconstruct the image exactly; lossy compression discards some information and may create blur, ringing, or colour artifacts.[1] Lossless does not mean “no file-size reduction”—it means the decoded pixels are preserved.[1]
A format can support more than one compression mode.[1] JPEG is lossy.[1] PNG is lossless.[1] WebP and AVIF can be encoded lossily or losslessly, so the format name alone does not tell you whether an export preserves every pixel.[1]
Choosing a format
- JPEG: a practical lossy choice for photographs when broad compatibility matters. It does not preserve transparency.[1]
- PNG: useful when exact pixel reproduction or transparency is important, such as screenshots, diagrams, and interface graphics. It may be larger than a lossy photo export.[1]
- WebP: supports both lossy and lossless encoding and transparency, and is widely supported in current browsers. Compare the actual result rather than assuming it will always be smallest.[1]
- AVIF: can produce compact still images and supports transparency, but check the target workflow and provide a suitable fallback when needed.[1]
- SVG: often a better fit for scalable logos, icons, and simple vector illustrations than a raster export.[1]
There is no universal “smallest format.” Image content, dimensions, encoder, quality setting, and transparency all affect the result.[1] Compare candidates at the size people will actually see, especially around text, fine lines, faces, gradients, and transparent edges.
A reliable export workflow
- Keep an untouched original and note its pixel dimensions and whether transparency matters.
- Decide the largest intended display size and whether the design needs a crop.
- Resize from the original and preserve its aspect ratio unless cropping is deliberate.
- Export likely format candidates. For photographs, compare a lossy option; for text-heavy graphics or transparency, include a lossless option.[1]
- Inspect the images at their displayed size and compare file sizes. Do not choose solely by a quality-number label: values are encoder settings, not a shared visual-quality scale.[2]
- Test the exported file in its real page or sharing destination. A content system may recompress it or strip metadata.
For HTML canvas exports, toBlob() accepts a requested MIME type and an optional lossy-quality value from 0 to 1. PNG is the required fallback: if the requested type is unsupported, the browser may still export PNG. Check the resulting blob's type and size rather than trusting only the requested extension or setting.[2]
Responsive delivery, accessibility, and privacy
A responsive page can offer multiple widths with srcset and use sizes to describe the image's expected layout width; the browser then selects a candidate.[4]
Use <picture> when you need art direction or format-specific sources with a fallback.[3][4]
Set intrinsic width and height so the browser can reserve the image's space, and provide meaningful alternative text for informative images.[4]
An empty alt is appropriate for a decorative image; compression itself does not make an image accessible.[3]
A local browser tool can resize a selected file without uploading it when its processing remains on the device. That does not guarantee that metadata was removed, that the result has no location information, or that another site will not upload it later. Check the output's metadata when privacy matters, and review the tool's behavior and policy before selecting sensitive files.
For production sites, generated variants still need sensible filenames, caching, format fallbacks, and testing on representative screens. Measure the bytes actually delivered—not just the local export—and avoid serving a needlessly large source to every visitor.[3][4]
Common questions
Does resizing always make an image smaller?
Reducing dimensions often reduces the amount of image data, but the exported file size also depends on format, compression settings, metadata, and image content.[1][4] Compare the actual output file.
Does compression always lower image quality?
Lossless compression preserves decoded pixels.[1] Lossy compression discards information and can reduce visible quality, particularly around text and sharp edges; inspect the exported image at its intended display size.[1]
Which image format makes the smallest file?
There is no single winner for every image. Compare formats at suitable settings for the particular photo, screenshot, illustration, or transparent graphic, and make sure the target browsers and workflow support the choice.[1]
Can I resize an image in my browser without uploading it?
A browser tool can process a locally selected image using browser APIs, but privacy depends on how that specific tool is implemented. For sensitive files, confirm that processing stays on-device and inspect the exported file's metadata.
What should I use for images on a responsive website?
Create image candidates appropriate to the rendered layout and use srcset with sizes so the browser can select a source. Use <picture> when you need explicit format fallbacks or different crops for different layouts.[3][4]
Sources
[1] Image file type and format guide - MDN
[2] HTMLCanvasElement: toBlob() method - MDN