Image optimisation for websites: formats, sizing, lazy loading and alt text
Choose WebP or AVIF, size images to their slot, compress, lazy-load below the fold, set width and height for CLS, and write alt text that helps.
The short answer
Serve photos as WebP or AVIF with a JPEG fallback, resize each image to the space it fills (and offer a smaller file for phones), compress it, lazy-load images below the first screen, and always set width and height so the page does not jump. Describe meaningful images in alt text and leave decorative ones empty.
Start by asking if you need the image
web.dev's first rule of image optimisation is that removing an image altogether is the best saving. Before compressing, ask whether CSS, a web font or plain text could do the same job. A stock photo of a handshake at the top of every page rarely earns its bytes.
Choose the right format
| Format | Best for | Notes |
|---|---|---|
| JPEG | Photographs | Lossy, no transparency. A good fallback for photos |
| PNG | Screenshots, logos, line art needing exact reproduction | Lossless with transparency, but large |
| WebP | A strong default for most raster images | Compresses better than JPEG, PNG and GIF; supported by modern browsers |
| AVIF | Best compression of the common formats | Newer, so offer a fallback; large files load all at once |
| SVG | Logos, icons, simple graphics | Stays sharp at any size |
MDN suggests lossless formats for screenshots, diagrams, logos and line art, where compression artefacts around text are easy to see, and lossy compression for photographs. For animation, web.dev recommends video instead of GIF, since GIF files are much larger.
To offer a modern format with a safe fallback, use the <picture> element: the browser takes the first source it supports and falls back to the <img>. Most WordPress, Shopify and Squarespace sites now convert uploads for you, so check your platform's settings before doing it by hand.
See what Website Care & Maintenance would cost for your business
Answer a few questions about your project and budget and get a personalised plan, compared with typical market prices.
Book a free 15-min callAbout 3 minutes · no obligation · fixed price confirmed in writingSize the image to its slot
An image 4,000 pixels wide shown in a 600-pixel column forces visitors to download pixels they never see. web.dev's example shows why this adds up fast: doubling an image's resolution quadruples its pixel count. A sensible rule is to export at about twice the displayed width for sharp screens, and no more.
MDN explains how to serve different files to different screens with srcset and sizes. In its example, a narrow viewport loads a 63 KB file instead of a 128 KB one. Most modern CMS platforms generate these variants automatically when you upload one good original. If yours does not, ask your developer to enable it.
Compress sensibly
- For photos, try several quality levels and pick the lowest one that still looks good. web.dev recommends this for JPEG rather than a fixed number.
- Strip unneeded metadata where your tool allows it.
- Compress once, from the original. Re-compressing an already compressed file degrades it further.
- Keep your originals in a separate folder so you can re-export later.
Lazy-load below the first screen only
Adding loading="lazy" to an image tells the browser to wait until it is close to the viewport. It needs no JavaScript library. But web.dev is firm on the exception: do not lazy-load images likely visible on load, especially the Largest Contentful Paint image. Doing so delays the most important picture on the page. For that image, keep default loading and consider fetchpriority="high".
Lazy loading works on <img> and <iframe>, not on CSS background images. If your hero is a background image, it will not be lazy-loaded, but it can be harder for the browser to discover early. Our Core Web Vitals guide explains why that matters.
Set width and height to stop layout jumps
Without dimensions, the browser does not know how much space to reserve, so text shifts when the picture arrives. That is Cumulative Layout Shift, and Google's good threshold is 0.1 or less. web.dev's fix: put width and height attributes on every image (modern browsers use them to work out the aspect ratio) and use height: auto in your CSS if you size images with it. The CSS aspect-ratio property also works. For responsive images, keep every variant at the same aspect ratio.
Write useful alt text
The W3C's alt decision tree boils down to four cases:
- Informative image: a short description that conveys the meaning.
- Decorative image: empty alt (
alt=""), so screen readers skip it. - Image in a link or button: describe where it goes or what it does.
- Image of text: put the same text in the alt.
Write for the person who cannot see the image, not for a search engine. "Plumber replacing a water heater" helps; "plumber Toronto best plumber cheap" does not. See our website speed guide for the wider picture.
Key takeaways
- Remove images you do not need, then use WebP or AVIF with a JPEG or PNG fallback.
- Resize to the displayed size and offer smaller files for phones with srcset.
- Lazy-load images below the fold, never the main image at the top.
- Always set width and height to avoid layout shift.
- Alt text describes meaning; decorative images get empty alt.
Frequently asked questions
Should I use WebP or AVIF?
WebP is a strong default with broad support. AVIF often compresses better but is newer and needs a fallback. If your platform converts automatically, let it. Otherwise WebP with a JPEG fallback is a safe, simple choice.
How big should website images be?
Match the displayed size, with up to double that width for sharp screens. There is no single file-size number that suits every site, so check the image warnings in PageSpeed Insights, and compress until quality just starts to drop.
Does lazy loading hurt SEO?
Not when used correctly. web.dev's warning is about speed: lazy-loading the main above-the-fold image delays it. Use native loading="lazy" on images further down and leave the top image on default loading.
Do I need alt text on every image?
Every image needs an alt attribute, but decorative images should have it empty. Informative ones need a short, accurate description. This helps screen reader users and is part of basic web accessibility.
Sources
- Choose the right image format — Google, web.dev, accessed November 2026
- Browser-level image lazy-loading for the web — Google, web.dev, accessed November 2026
- Optimize Cumulative Layout Shift — Google, web.dev, accessed November 2026
- Responsive images — MDN Web Docs, accessed November 2026
- Image file type and format guide — MDN Web Docs, accessed November 2026
- An alt Decision Tree — W3C Web Accessibility Initiative, accessed November 2026
How Flowmatix can help
We put this into practice for businesses in Toronto and around the world through our Website Care & Maintenance, web development services. Want to know what it would take for your business? Get a personalised quote in about 3 minutes, or request a free website check-up.
More on Websites & Design
What an auto repair shop website needs in Ontario: jobs, estimates, booking
What an Ontario auto repair shop website needs: service pages by job, a booking form that respects estimate rules, and honest pricing language.
November 14, 2026 · 5 min readWebsites & DesignWhat a banquet hall website needs: capacity, availability and alcohol rules
What an Ontario banquet hall website needs: capacity, availability enquiries, AGCO liquor licence info and packages without fake prices.
November 14, 2026 · 5 min readWebsites & DesignBefore and after photos for your website: consent, layout, alt text and speed
Before and after photos on a business website: client consent in Canada, layout, compression, alt text, captions and a gallery that loads fast.
November 14, 2026 · 6 min readGot a project in mind?
Book a free 15-minute strategy call. We talk through what you need, then you get a fixed price in writing before any work starts. No sales script.