Image sizes for the web
Pixels, aspect ratios, DPI and responsive images
Why pixel dimensions are the only size that matters on screen, how device pixel ratio changes what you should export, how aspect ratios are calculated, what fit, fill, crop and pad really do, and how srcset, sizes and width/height attributes fit together.
- By HelpMeJPG editorial team
- Published
- Updated
- 9 min read
On this page
“What size should this image be?” has three different answers depending on whether you mean pixels, bytes or the space it takes up on the page, and most sizing problems come from mixing them up. This guide covers the first and third: how dimensions, aspect ratios and screen density interact, how resizing modes differ, and how to tell the browser what you want so pages do not jump about while images load.
Pixels are the only real size
A bitmap image has exactly one intrinsic size: its width and height in pixels. A 1200×800 photograph contains 960,000 pixels whether it is shown on a phone, a monitor or a billboard; how large it appears depends entirely on the device drawing it.
DPI (dots per inch) and PPI (pixels per inch) describe how densely those pixels should be packed when the image is printed. A 3000-pixel-wide photo printed at 300 pixels per inch is 10 inches wide; the same file at 150 pixels per inch is 20 inches wide and visibly softer. The number is stored as metadata – the density fields in a JPEG's JFIF header, or the pHYs chunk in a PNG – and changing it changes no pixels at all. Print and layout software reads it to decide the physical size; browsers ignore it completely, mapping image pixels to CSS pixels and scaling by whatever the stylesheet and markup ask for. If a client asks for a “300 DPI web image”, what they need is enough pixels for the largest size at which it will be displayed.
The dimensions checker shows the pixel dimensions, the stored density if any, and the resulting print size, which settles this conversation quickly.
Device pixel ratio and 2× assets
A CSS pixel is not a device pixel. Phones, tablets and many laptops pack two or three physical pixels into each CSS pixel; the ratio is exposed to scripts as window.devicePixelRatio. An image displayed in a 400 CSS-pixel box on a 2× screen is drawn across 800 device pixels, so a file only 400 pixels wide is stretched and looks soft, especially around text and fine line work.
The remedy is to export at the display size multiplied by the pixel ratio – a “2× asset” – and let the browser scale it down. The cost is that a 2× image has four times as many pixels as a 1× image, and a 3× image nine times. For photographs this is partly offset because a larger image tolerates a lower quality setting: artefacts are smaller relative to the display size and are averaged away when the image is scaled down. For interface graphics and logos the cleaner answer is usually SVG, which has no fixed pixel size, as the format guide explains.
Working out an aspect ratio
The aspect ratio is the width divided by the height, written as two whole numbers with no common factor. To simplify it, divide both dimensions by their greatest common divisor (GCD). Euclid's algorithm finds it quickly: for 1920×1080, 1920 ÷ 1080 leaves a remainder of 840; 1080 ÷ 840 leaves 240; 840 ÷ 240 leaves 120; 240 ÷ 120 leaves nothing, so the GCD is 120 and the ratio is 16:9. Not every size reduces to something familiar: 1366×768 reduces only to 683:384, very close to 16:9 but not exactly, which is why an aspect ratio calculator reports both the exact ratio and the nearest common one.
To find a missing dimension, keep the ratio constant: a 3:2 image resized to 900 pixels wide must be 600 pixels tall, because 900 × 2 ÷ 3 = 600.
| Ratio | Decimal | Example sizes | Where you meet it |
|---|---|---|---|
| 16:9 | 1.78 | 1280×720, 1920×1080, 3840×2160 | Video, presentation slides, video thumbnails, wide hero banners |
| 4:3 | 1.33 | 1024×768, 1600×1200, 2048×1536 | Older displays, many tablets, compact cameras and phones |
| 3:2 | 1.50 | 1080×720, 3000×2000, 6000×4000 | Most interchangeable-lens camera sensors, 6×4 inch prints |
| 1:1 | 1.00 | 400×400, 1080×1080 | Avatars, product grids, square social posts |
| 9:16 | 0.56 | 1080×1920 | Vertical video and “stories” formats |
| 4:5 | 0.80 | 1080×1350 | Portrait social posts |
| 1.91:1 | 1.91 | 1200×630 | Link preview images (Open Graph) |
Fit, fill, crop or pad
When the target has a fixed width and height and the source has a different ratio, something has to give. Tools name the options inconsistently, so it is worth being precise about what each does.
| Mode | What happens | Output size | Distortion | Content lost |
|---|---|---|---|---|
Fit (CSS object-fit: contain) |
Scales the image until it touches the box on one axis | One side may be shorter than the box | None | None |
Fill / stretch (CSS object-fit: fill) |
Scales each axis independently to the box | Exactly the box | Yes | None |
Crop / cover (CSS object-fit: cover) |
Scales to cover the box, trims the overflow | Exactly the box | None | Edges on one axis |
| Pad / letterbox | Fits the image, then fills the remaining area with a colour or transparency | Exactly the box | None | None |
Fit is right when nothing may be cut off and the layout tolerates varying sizes. Crop is right when every output must be identical – thumbnails, cards, avatars – and you accept losing the edges; choose the focal point deliberately rather than always cropping from the centre, which the cropper lets you do. Pad is for strict dimensions where cropping is unacceptable, such as product images against white. Stretching is almost never right: faces, circles and type look wrong at even a few percent of distortion. The image resizer offers all four modes under these names, and the batch resizer applies one mode to every file, where the choice matters most, since a batch rarely shares one aspect ratio.
The limits of upscaling
Downscaling throws pixels away and, with a decent filter, loses little the eye can see. Upscaling has to invent pixels, and no interpolation method – nearest neighbour, bilinear, bicubic, Lanczos – can invent detail the camera never captured. The result is a larger image no sharper than the original, with blur or ringing along edges depending on the filter. Modest enlargements of soft photographic content are often tolerable; enlarging screenshots, text or line art is not, and the fix is to go back to the vector source or re-export larger.
Pixel art is the exception: scaled by a whole-number factor with nearest-neighbour interpolation (CSS image-rendering: pixelated), it stays crisp by design. For everything else treat upscaling as a last resort; the resizer flags it whenever a target exceeds the source.
Responsive images: srcset, sizes and picture
One file cannot be right for a 360-pixel phone at 3× and a 1440-pixel desktop at 1×. The srcset attribute lists several versions of the same image with their real widths, and sizes tells the browser how wide the image will be displayed at each viewport width. The browser multiplies the display width by the device pixel ratio and picks the smallest candidate that is large enough.
<img
src="/img/hero-1200.jpg"
srcset="/img/hero-600.jpg 600w, /img/hero-1200.jpg 1200w, /img/hero-1800.jpg 1800w"
sizes="(max-width: 720px) 100vw, 720px"
width="1200"
height="800"
alt="Harbour at dusk with the city skyline behind"
/>
The sizes value must describe the layout honestly: here the image spans the viewport on narrow screens and is capped at 720 CSS pixels otherwise. If sizes is omitted the browser assumes the image is as wide as the viewport and over-fetches on every desktop. For images that are always the same CSS size, such as a logo, use density descriptors instead: srcset="logo.png 1x, logo@2x.png 2x".
The <picture> element adds two things srcset cannot: switching formats, and switching to a differently cropped image at certain widths (“art direction”).
<picture>
<source type="image/avif" srcset="/img/hero.avif" />
<source type="image/webp" srcset="/img/hero.webp" />
<img src="/img/hero.jpg" width="1200" height="800" alt="Harbour at dusk" />
</picture>
The browser uses the first <source> whose type it supports and otherwise falls back to the <img>; each <source> can carry its own srcset and sizes. The guide to optimising images shows how this fits into the wider performance picture.
Width and height attributes stop layout shift
When the browser knows an image's dimensions before it downloads, it reserves the right amount of space; when it does not, the text below jumps down as the image arrives. That jump is Cumulative Layout Shift, one of the Core Web Vitals, and Google's threshold for a “good” score is a CLS of 0.1 or less. Modern browsers compute an image's aspect ratio from its width and height attributes, so the fix is simple: always include them with the intrinsic pixel dimensions, and let CSS handle the display size with width: 100%; height: auto. The attributes only tell the browser the shape, not the displayed size. For responsive images, give them the dimensions of the fallback src; what matters is the ratio, which all candidates share. If the ratio is set by the design rather than the file, the CSS aspect-ratio property reserves space the same way.
How large should the files be?
There is no universal correct size: the right dimensions depend on how wide the image is displayed in your layout and on the densest screen you choose to serve properly. The ranges below are starting points to adapt to your design, not benchmarks.
| Role | Typical displayed width | Export width to consider | Notes |
|---|---|---|---|
| In-article image | 600–800 CSS px | 1200–1600 px | One size at 2× often suffices; add a 1× candidate for mobile data |
| Full-width hero | Up to 1400–2000 CSS px | Several candidates, e.g. 800, 1200, 1600, 2400 px | Use srcset; crop differently for portrait phones with <picture> |
| Thumbnail or card | 150–400 CSS px | 300–800 px | Crop to a fixed ratio so the grid aligns |
| Link preview (Open Graph) | Fixed by platforms | 1200×630 px | Keep text away from the edges |
Dimensions come before format and compression, because removing pixels saves more bytes than any quality setting, and a correctly sized image compresses faster and looks better.
A sizing workflow
- Measure the largest CSS width at which the image will be displayed, at every layout breakpoint.
- Multiply by the highest pixel ratio you intend to serve well – usually 2× – to get the largest export width.
- Decide the aspect ratio for the slot, and whether sources will be fitted, cropped or padded to it.
- Export the candidates you need, resizing down from the original, never up, and write the
<img>withsrcset, an honestsizes, andwidthandheightattributes. - Check the result with the dimensions checker and on a real high-density screen before signing off.
Try it: Image Resizer to export each width, then Image Dimensions Checker to confirm the results.
Every resizing tool on this site runs in your browser and shows the exact output dimensions before you download.
Sources and further reading
- MDN – <img>: The Image Embed element (srcset, sizes, width and height)
- MDN – <picture>: The Picture element
- MDN – Window: devicePixelRatio property
- MDN – CSS object-fit
- web.dev – Learn Images (responsive images chapters)
- web.dev – Optimize Cumulative Layout Shift
- W3C – PNG Specification (Third Edition), pHYs physical pixel dimensions chunk
About the author
HelpMeJPG editorial teamEditorial team
The people who build and maintain the HelpMeJPG tools. Guides are written from the tools' own behaviour and the standards they implement, and are revised whenever a tool changes.