Image optimisation for websites: formats, sizes and lazy loading
Image optimisation for the web, step by step: which format to use, what size to export, how much to compress, lazy loading, alt text and when a CDN helps.
Design, web and motion studio in Dubai
To optimise images for a website, choose the right format (WebP or AVIF for photos, SVG for logos), resize each image to roughly twice the width it displays at, compress it until the file is small but still looks clean, lazy load everything below the first screen, and give every image a width, height and alt text. Done well, this is often the quickest way to make a slow page faster.
This guide gives you the formats, sizes and settings, plus a routine you or your team can follow every time you upload a picture.
Key takeaways
- Use WebP or AVIF for photos and SVG for logos and icons; keep JPEG for email and print, and PNG for sharp graphics.
- Export images at about twice the width they display at, never at camera size, and let the site serve smaller versions to phones.
- Lazy load images below the first screen, but never the hero image, which should load first.
- Always set a width and height, and write alt text that describes what the image shows.
Why images matter for speed and search
Images are usually the heaviest files on a page. One uncompressed photo can weigh more than all the page's code put together, and on a phone connection that weight turns into seconds of waiting. The largest image on screen is often what Google measures as Largest Contentful Paint, one of its Core Web Vitals.
Images also help people find you. Google Images, product results and AI answers all read file names, alt text and the words around an image. A well-prepared image works for speed, accessibility and search at once.
Which image format to use
For most sites the practical answer is WebP, with AVIF as a bonus if your platform creates it automatically. Shopify and many image CDNs can serve modern formats to browsers that support them without any action from you; on WordPress, an image plugin or your host can convert your library.
| Format | Best for | Watch out for |
|---|---|---|
| JPEG | Photos, especially for email and print | No transparency; larger than WebP or AVIF at the same quality |
| PNG | Screenshots and graphics with sharp edges or transparency | Very large for photographs |
| WebP | Photos and graphics on the web, with or without transparency | Some email programs and older tools still prefer JPEG |
| AVIF | Photos where the smallest file matters most | Slower to create; check your platform and tools support it |
| SVG | Logos, icons and simple illustrations | Only upload SVGs from trusted sources, because they can contain code |
| GIF | Very little today | For animation, a short MP4 or WebM video is usually far smaller |
What size to export images at
Most sites are slowed by images far bigger than they ever appear. A photo straight from a phone can be 4,000 pixels wide or more, while most screens show it at a fraction of that. Export at about twice the width the image displays at, which keeps it sharp on high-resolution screens, and no larger.
| Use | Typical display width | Export width | Rough file size target |
|---|---|---|---|
| Full-width hero or banner | Full screen | 1,920 to 2,560 px | Under about 250 KB |
| Image inside page content | 600 to 800 px | 1,200 to 1,600 px | Under about 150 KB |
| Product photo with zoom | Varies | Your platform's recommended size | Under about 300 KB |
| Card or thumbnail | 300 to 400 px | 600 to 800 px | Under about 60 KB |
| Logo or icon | Any | SVG, which scales to any size | A few KB |
Rules of thumb, not limits
Treat the file sizes as targets, not hard limits; a detailed photo may need more. Store platforms such as Shopify publish their own recommended product image dimensions, which change from time to time, so check their help pages at the time you shoot. Our guide to product photos for online stores covers shooting, backgrounds and angles.
How much to compress
Compression removes detail the eye barely notices. For JPEG and WebP, a quality setting somewhere around 70 to 85 usually looks the same as the original at normal viewing size, while cutting the file size sharply. Go much lower and you will see blotches in skies, skin and smooth gradients.
- Compress before uploading with a tool such as Squoosh, or let a plugin or CDN do it on upload.
- Check the result at full size on a good screen, especially faces, products and any text.
- Do not re-save the same JPEG over and over; each save loses detail. Keep the original and export fresh.
- Strip hidden metadata such as camera details and GPS location, which adds weight and can reveal where a photo was taken.
Keep important text out of images
Text baked into an image is harder for search engines and screen readers to read, blurs when compressed, and cannot be translated or edited easily. Put headlines and prices in real text on top of the image instead.
Responsive images: the right file for each screen
A phone does not need the same file as a large desktop monitor. Responsive images give the browser a set of sizes (written in the page code as srcset and sizes) and let it download the smallest one that still looks sharp.
- WordPress creates several sizes of each upload and adds responsive code automatically, as long as the theme uses its standard image functions.
- Shopify's image CDN serves resized versions, and themes request the sizes they need.
- Next.js and similar frameworks have image components that resize and convert images automatically.
- Page builders and hand-coded sections sometimes bypass these systems, so check what a phone actually downloads.
A two-minute check
Open the page in your browser's developer tools, switch to a phone-sized view, and look at the Network tab filtered to images. If a phone is downloading a 2,500-pixel hero, responsive images are not working.
Lazy loading, done right
Lazy loading tells the browser to wait before fetching an image until the visitor scrolls near it. Modern browsers support this with a single attribute (loading set to lazy), and WordPress adds it automatically to most images.
- Lazy load every image below the first screen. This saves data and speeds up the first view.
- Never lazy load the hero image or anything visible on arrival; it delays the main content.
- Give the hero image a high fetch priority (the fetchpriority attribute set to high) so the browser downloads it first.
- Avoid putting the hero image in a CSS background or a slider, which both hide it from the browser until later.
- Always include a width and height, or an aspect ratio, so the browser reserves space and the page does not jump as images arrive.
Alt text and file names
Alt text is a short description of an image, read aloud by screen readers and used by search engines to understand it. Write what the image shows and why it is there, in plain words, as you would describe it over the phone.
| Image | Weak alt text | Better alt text |
|---|---|---|
| Team photo on an About page | image1 | Installation team standing beside a branded van |
| Product photo | best leather bag cheap buy now | Tan leather tote bag with brass buckle, front view |
| Decorative divider | line | Leave the alt text empty, so screen readers skip it |
| Chart in an article | chart | Bar chart of enquiries by month, highest in March |
Name files before you upload
A file called tan-leather-tote-front.jpg tells search engines more than IMG_4821.jpg. Our website accessibility basics cover alt text alongside the other common accessibility fixes.
CDNs and an upload routine
A content delivery network (CDN) keeps copies of your images on servers around the world and serves each visitor from the nearest one. Image CDNs go further, resizing and converting images on the fly. Shopify includes one, many WordPress hosts include one, and services such as Cloudflare can add one in front of any site. A CDN does not fix oversized originals, though, so a routine still matters.
On an image-led store such as the Shopify store we built for Doré, a Dubai fine jewellery house, the photos are what customers are buying from, which is exactly where this routine earns its keep.
Image upload routine
- Crop to the shape the layout needs.
- Resize to about twice the display width.
- Export as WebP, or JPEG if your platform converts automatically.
- Compress, then check faces, products and edges at full size.
- Rename the file in plain words, separated by hyphens.
- Write alt text that describes the image, or leave it empty if it is purely decorative.
- Make sure the hero image is not lazy loaded.
- Test the page on a real phone.
Getting help
Our free website check reports your homepage's page weight and server response in plain words. If you would like someone to resize and convert an existing image library, our website fixes and care plans start from $49. For WordPress sites, our guide to speeding up WordPress safely covers the rest of the speed work.
Frequently asked questions
Is WebP better than JPEG for websites?
Usually, yes. WebP files are typically noticeably smaller than JPEGs of similar visual quality, and WebP supports transparency, which JPEG does not. All modern browsers display WebP. Keep JPEG for email newsletters and for files you send to printers or partners, where older software may not accept WebP.
What is the best image size for a website?
There is no single size. Export each image at about twice the width it displays at: around 1,920 to 2,560 pixels wide for a full-screen hero, 1,200 to 1,600 for an image in the content area, and 600 to 800 for a thumbnail. Then compress it, and let responsive images serve smaller versions to phones.
Does lazy loading help SEO?
Indirectly. Lazy loading images below the first screen makes pages load faster, which helps visitors and Core Web Vitals, and Google can see images lazy loaded with the standard browser attribute. The mistake to avoid is lazy loading the main image at the top of the page, which slows the loading measurement Google uses.
Does every image need alt text?
Every image needs an alt attribute, but not every image needs a description. Images that carry meaning, such as products, people, charts or images used as links, need alt text that describes them. Purely decorative images, such as background patterns and dividers, should have empty alt text so screen readers skip them.
The Dawnwire Agency Deck
Our process, what each service includes, how we price and hand over, and a selection of real client work, in one free deck.