How to optimise images for a website, and how large they should be
Pixel sizes for common layouts, sensible file size budgets, the right format for each kind of image, and the loading attributes that make pages feel fast.
Websites and developers · 2 min read · Updated
Size images for how they are displayed
The right width for an image is the width it is shown at, multiplied by the screen's pixel density. An image displayed 800 CSS pixels wide needs 800 pixels on a standard screen and about 1600 on a high-density screen such as most phones and many laptops. Anything larger is downloaded and then thrown away by the browser.
Typical widths
As a starting point, before srcset lets each device choose:
- Full-width hero or banner images: 1920 to 2560 pixels wide.
- Images inside an article column: 1200 to 1600 pixels.
- Cards and thumbnails: 400 to 800 pixels.
- Logos and icons: SVG where possible, otherwise twice the displayed size.
- Open Graph link previews: 1200 × 630 pixels.
File size budgets
There is no official limit, but with modern formats a large hero image can usually be kept to roughly 200 to 300 KB, content images to about 150 KB and thumbnails to about 50 KB. The largest image near the top of a page often decides how quickly the page appears to load, so spend the most effort there.
Pick the format for the content
- Photos: WebP or AVIF, with JPG as a fallback where needed.
- Screenshots and interface images: lossless WebP, or PNG with a reduced palette.
- Logos, icons and diagrams: SVG.
- Animations: animated WebP or a short video instead of GIF, which is usually several times larger.
Loading, layout and metadata
- Set width and height on every img element so the browser reserves space and the layout does not jump as images arrive.
- Lazy-load images below the first screen with loading="lazy". Load the main image at the top normally, and consider fetchpriority="high" for it.
- Use srcset and sizes so phones download smaller files than desktops.
- Strip metadata. Camera EXIF adds bytes and can expose a location. Compress Image removes it by default.
A quick workflow
- Resize to the largest size the image is displayed at, or generate several widths with Responsive Images.
- Convert photos to WebP or AVIF, or let Format Shoot-out pick the smallest format at equal visual quality.
- Compress with the For a website preset, which saves WebP no wider than 1920 px.
- Check the result side by side with the original before publishing.
Tools in this guide
- Compress ImageShrink JPG, PNG, WebP, AVIF and GIF files with MozJPEG, OxiPNG and modern codecs, with a live before/after preview.
- Resize ImageResize to exact pixels, a percentage or a longest side, with Lanczos3 and Magic Kernel resampling. Batch ready.
- Responsive ImagesGenerate WebP/AVIF/JPG widths plus ready-to-paste picture, srcset and sizes markup.
- Convert to WebPConvert any image (HEIC, PNG, WebP, AVIF, RAW, PSD, SVG and 26 more) to WebP in bulk, right in your browser.
- Format Shoot-outNewEncodes your image as JPG, WebP and AVIF at the same visual quality and keeps the smallest one.
- Remove MetadataStrip EXIF, GPS, XMP, IPTC and comments losslessly. Pixels are never re-encoded for JPG, PNG and WebP.
Related guides
- Responsive images with srcset and sizes, explained
- How to create an Open Graph image for link previews
- Image to Base64 and data URIs: when to inline images, and when not to
- How to generate a complete favicon set