Websites and banners, made understandableImages · Code · WordPress
Home / Guides
Images

Resize a photo without losing useful detail

Pixel dimensions, file size and displayed size are different quantities. First decide where the image will appear, then prepare the pixels it needs, and finally tune compression.

Before you begin

Keep the original untouched. For a 4000 × 3000 px photograph displayed at 800 CSS pixels, prepare 800 px and 1600 px variants. The larger version can serve high-density screens; it need not be downloaded by every visitor.

Resize a photo without losing useful detail. 4000 × 3000 → 1600 × 1200 → 800 × 600
4000 × 3000 → 1600 × 1200 → 800 × 600
Text explanation of the diagram

4000 × 3000 → 1600 × 1200 → 800 × 600. Resizing from 4000 × 3000 to 1600 × 1200 reduces the pixel count from 12 million to 1.92 million: an 84% reduction. The file does not necessarily become 84% smaller; content and encoding also matter.

The procedure

  1. Open Image → Image Size. Link the dimensions and enable Resample when changing the pixel count. Enter 1600 px for width: a 4:3 image becomes 1200 px high.
  2. Save the editable document separately and export a web copy. Start with JPEG or WebP for a photograph. Compare quality settings at 100%, paying attention to hair, lettering and thin lines.
  3. Reopen the exported file. Check dimensions, colour, sharpness and actual file size. Use srcset for the variants and provide width/height so the browser can reserve space.
Code example
<img src="photo-800.jpg" srcset="photo-800.jpg 800w, photo-1600.jpg 1600w" sizes="(max-width: 800px) 100vw, 800px" width="1600" height="1200" alt="Описание фотографии">

A worked example

Resizing from 4000 × 3000 to 1600 × 1200 reduces the pixel count from 12 million to 1.92 million: an 84% reduction. The file does not necessarily become 84% smaller; content and encoding also matter.

Check the result

Test on a narrow screen and a high-density display. Inspect Network to see which file the browser actually selected. A small editor thumbnail cannot demonstrate export quality.

A common mistake

Changing 300 ppi to 72 ppi without resampling does not reduce a web image’s pixel dimensions. PPI connects pixels to printed size; browsers primarily need the correct pixel dimensions.

Sources and next steps

Diagram and examples: Web Article. The diagram explains a principle; it is not an interface capture or a software test result.

Check the chosen file, not only the displayed width

The working example below uses two original teaching images of the same scene, 400 and 800 pixels wide. Its real slot is capped at 400 CSS pixels. You can inspect srcset, sizes and currentSrc against actual files rather than the absent photo-800.jpg in a code fragment.

  1. Open the example at narrow and wide widths. sizes describes (max-width: 468px) calc(100vw - 68px), 400px. CSS sets the same cap; inspect the real width because its parent can constrain it further.
  2. Compare slot width and devicePixelRatio. At a 292 CSS-pixel slot, DPR 1 suggests 292 image pixels and DPR 2 suggests 584; at 400 CSS pixels, the corresponding figures are 400 and 800. These are selection inputs, not a guaranteed browser decision.
  3. Read the displayed currentSrc and the corresponding file size. A resized window may keep a larger file already loaded. For a fresh comparison, reopen at the intended width and record the conditions.
Check the chosen file, not only the displayed width — 292 CSS px × 1 / 2; 292 / 584 image px; 400w / 800w
Check the chosen file, not only the displayed width — 292 CSS px × 1 / 2; 292 / 584 image px; 400w / 800w

Worked record

Two real filesscene-400.png and scene-800.png are original explanatory artwork, not archival photographs.
Exact HTMLThe real src, 400w/800w srcset, sizes and width/height appear below. Both file paths are available.
Check recordViewport __; slot __; DPR __; currentSrc __; selected file bytes __; fresh navigation or resize __.
Testing boundaryThe displayed DPR is the actual value. Changing viewport width alone does not emulate another display density.
<img src="/assets/editorial-20261024/scene-400.png" srcset="/assets/editorial-20261024/scene-400.png 400w, /assets/editorial-20261024/scene-800.png 800w" sizes="(max-width: 468px) calc(100vw - 68px), 400px" width="800" height="600" alt="Teaching composition of three rectangles">
Teaching composition of three rectangles

Pixel count does not determine file size linearly. The dimensions and byte counts apply to these PNGs; assess photographic quality and encoding separately.

Primary sources: MDN: img, srcset and sizes

An early image request does not remove a late insertion

After choosing dimensions, check when the browser discovers the image. fetchpriority="high" hints at the priority of an already known resource; it does not run deferred JavaScript sooner. A preload can reveal a URL earlier. First identify the actual LCP element: it may be text.

  1. Download the complete example and extract it into a separate working folder. With Python 3 and no extra packages, run python3 -m http.server 9460. Open http://localhost:9460/a.html, then b.html and c.html. Use HTTP, not file://, for comparable requests.
  2. A includes an ordinary img in the initial HTML. B inserts the same element after 300 ms with high fetch priority. C keeps that insertion delay but declares the same PNG early with link rel="preload" as="image". All three use one asset, dimensions and styling.
  3. Do not click or scroll until the result appears. Record the request’s startTime and LCP; confirm that element is hero. Repeat three times at each width. An unavailable API is reported explicitly; a missing observation is not zero.
  4. Match viewport, zoom, network, cache and exact resource URL. Inspect Network for duplicate requests. Our local server returned Cache-Control: no-store; these runs used neither network throttling nor a simulated phone.

Observed here: medians of three loads per combination in the built-in browser on 7 November 2026, milliseconds from navigation start. All 18 final LCP observations identified hero. An initial pass captured before observation delivery completed is retained separately and excluded.

2026-11-07 · localhost · 3×
WidthA/B/CRequest, msLCP, ms
360a12.172
360b329.1376
360c10.5360
1280a1056
1280b325.5364
1280c9.2364

C requested the file earlier than B, while LCP remained near the delayed insertion. At 1280 px C’s median was no better than B’s: this small series does not demonstrate an LCP improvement. A did not wait for a timer. This is a controlled example with an artificial delay, not field Core Web Vitals or evidence that our site became faster.

Apply the method: first expose the key image in initial HTML and avoid lazy-loading it without a reason. If CSS or JavaScript genuinely hides the resource, evaluate one appropriate preload. Match URL, as, format, responsive candidate and CORS mode to the actual consumer; verify that two requests are not made. Do not assign high priority to every image. The example’s decorative PNG deliberately weighs 1,955,456 bytes; it is not an example of an efficient publishing size.

Record: page/conditions ___; LCP element ___; resource URL ___; discovery method ___; request start/end ___; insertion time ___; LCP ___; repeat count ___; errors/duplicate requests ___; field data after the change ___. An earlier request alone does not prove earlier rendering.

ZIP · HTML/CSS/JS + PNG · CC BY 4.0 · JSON · 18 observations

<link rel="preload" as="image" href="hero.png" fetchpriority="high">
<!-- Same URL is used by the delayed image in c.html. -->

MDN · fetchpriority

HTML requests immediately; JavaScript waits 300 ms; preload requests early while insertion still waits 300 ms.
Three paths to one image. Original example and measurements; Web Article · CC BY 4.0.

web.dev · Optimize Largest Contentful Paint · updated 2025-03-31

Keep making

Eager in the first viewport, lazy below: inspect two images

After choosing image dimensions, decide which picture the reader should see immediately. Keep that image on the ordinary eager path: loading="eager", or no loading attribute. For an illustration far below the first viewport, test loading="lazy". This is a browser hint, not a promise to start the request at the exact moment of scrolling. “Below the heading” is not the same as “outside the first viewport”: actual page geometry matters.

Compare two real files

Open the A/B example or download all HTML, CSS, JS and PNG files as a ZIP. This is a separate native-loading exercise: both image elements already exist in the initial HTML. There is no preload, delayed insertion or fetchpriority. Two original PNGs have the same 768 × 480 dimensions, but distinct URLs and slightly different colours. A cached entry for one file therefore cannot stand in for observing the other.

  1. Open the example afresh at 360 px and, separately, at 1280 px. Record browser, viewport height, zoom, DPR, network and cache conditions. A narrow window alone does not reproduce a complete phone environment.
  2. Before scrolling, inspect A near the page start. It has eager loading. Record whether the picture appears, its naturalWidth/naturalHeight and its Resource Timing entry. The expected intrinsic dimensions are 768 × 480; zero means a decoded image is not available yet.
  3. Check B’s position. The example deliberately leaves a gap of at least four viewport heights before it. This is an experimental condition, not advice to put empty stretches into an article. Select “Record current state” and save the observation.
  4. Scroll to B or follow its jump link. Record again. A request that started before B entered the viewport is compatible with lazy loading: the browser decides its advance-loading distance.

Read incomplete and boundary results honestly

The example distinguishes pending, loaded and failed/unavailable. The complete flag alone is insufficient: it can be true for a broken image, so naturalWidth is checked too. An unavailable Resource Timing API or a missing matching entry is reported explicitly, rather than presented as a successful zero measurement. A zero transferSize also does not prove that no request happened: cache may be involved. Inspect the exact URL in Network to resolve the case.

Both images declare width and height; CSS preserves their proportions when shrinking. Lazy loading does not require deleting those dimensions. With JavaScript disabled, browsers do not defer native lazy images in the same way; the pictures and links in this example remain ordinary HTML. Its script only displays local observations and sends nothing to a server.

Filled markup review: A — eager, near the start, 768 × 480; B — lazy, after a deliberately long gap, 768 × 480; two separate PNGs; both elements in initial HTML. Your observation record: browser/viewport ___; cache/network ___; B position before scrolling ___; B request before/after ___; error ___; conclusion ___. Do not invent a timing: a reading describes that particular run, rather than the site’s speed for every visitor.

Image A sits in the first viewport with eager loading; B is far below with lazy loading. The browser may request B before it appears.
A uses ordinary eager loading; the browser chooses B’s advance-request timing. Diagram: Web Article · CC BY 4.0.

MDN · HTMLImageElement: loading property