# Image optimization: WebP, AVIF, sizes and alt text

Serve AVIF or WebP with a JPEG or PNG fallback, give each image a set of sizes through srcset and sizes, set width and height to stop layout shift, lazy-load only images below the fold, and write alt text that describes what the image means on that page. Those five habits cover most of the speed and accessibility gains.


## What good image optimization looks like

Good image optimization means every visitor downloads the smallest file that still looks sharp in the space it fills, the page does not jump while images load, and people using screen readers get the same information as everyone else. In practice that comes down to five habits: a modern format with a fallback, responsive sizes, fixed dimensions, sensible lazy loading, and alt text written for the page the image sits on.

Images are usually the heaviest part of a small business page. A single uncompressed hero photo from a phone or a stock library can outweigh all the HTML, CSS and JavaScript on the page combined. Fixing images is often the fastest speed win you can get without touching the design, which is why we treat it as a build standard on every [website development](https://tcomconsultants.com/services/website-development/) project rather than an afterthought.


## Choosing a format: JPEG, PNG, WebP, AVIF or SVG

WebP is the safe modern default. Google's own documentation says [WebP lossless images are 26% smaller than PNGs and lossy WebP images are 25 to 34% smaller than comparable JPEGs](https://developers.google.com/speed/webp) at the same measured quality. It also supports transparency, so it can replace many PNG logos and cut-outs.

AVIF usually goes further. The web.dev guide on [AVIF](https://web.dev/learn/images/avif) reports significant file size reductions compared with both JPEG and WebP, and notes it has been supported in Chrome since 2020, Firefox since 2021 and Safari since 2022. The catch is that a browser that cannot decode a format simply shows nothing, so you still need a fallback.

| Format | Best for | Watch out for |
|---|---|---|
| AVIF | Photos and large hero images where every kilobyte counts | Slower to encode; always provide a fallback |
| WebP | General photos, product shots, transparent graphics | Very old browsers need a JPEG or PNG fallback |
| JPEG | Fallback for photos, email images | No transparency; larger than modern formats |
| PNG | Fallback for screenshots and graphics with sharp edges | Large files for photographic content |
| SVG | Logos, icons, simple illustrations | Not suitable for photos; sanitize uploaded SVG files |


### When to keep JPEG or PNG

Keep the older formats as the fallback inside a picture element, and use them on their own where modern formats are not accepted, such as many email clients or some third-party platforms. Google Search supports BMP, GIF, JPEG, PNG, WebP, SVG and AVIF, so format choice will not hurt indexing as long as the file extension matches the real file type.


## Serving the right size to every screen

A phone with a 400-pixel-wide screen does not need the 2,400-pixel image you send to a large desktop monitor. The srcset attribute lists several versions of the same image at different widths, and the sizes attribute tells the browser how wide the image will display. The browser then picks the smallest file that will look sharp on that device.


### Writing srcset and sizes

Most content management systems and image services can generate the different widths for you. Your job is to decide which widths to make and to describe the layout honestly.


#### Pick your widths

Look at how wide the image ever displays across your breakpoints, then multiply by two for high-density screens. A content image that tops out at 800 pixels wide might get versions at 400, 800, 1200 and 1600 pixels. Producing ten versions rarely helps; four or five is usually enough.


#### Describe the slot with sizes

If an image fills the full width on mobile and half the width on desktop, sizes should say exactly that. When sizes is missing, browsers assume the image is as wide as the screen and often download a far bigger file than needed. Google also recommends keeping a plain src on the img element as a fallback because some browsers and crawlers ignore srcset.


### Width, height and layout shift

Always put width and height attributes on images, or use the CSS aspect-ratio property. That lets the browser reserve the right space before the file arrives, so text and buttons do not jump down the page as images load. Visitors notice that jump, and Google measures it as Cumulative Layout Shift.


## Loading: lazy, eager and the hero image

The loading="lazy" attribute tells the browser to wait until an image is close to the viewport before downloading it. That saves data on long pages. The web.dev guide on [browser-level lazy loading](https://web.dev/articles/browser-level-image-lazy-loading) is clear that you should not lazy-load images likely to be visible when the page first opens, because it delays your largest, most important image.

- Hero image and logo: load normally, and consider fetchpriority="high" on the hero.
- Images further down the page: add loading="lazy".
- Carousels: load the first slide normally and lazy-load the rest.
- Background images set in CSS: these ignore the loading attribute, so keep them small.


## Alt text that helps people and search

Alt text is read aloud by screen readers and shown when an image fails to load. The W3C [images tutorial](https://www.w3.org/WAI/tutorials/images/) sorts images by purpose, and the purpose decides what you write.

- Informative images: a short description of the information the image adds.
- Decorative images: an empty alt attribute (alt="") so screen readers skip them.
- Functional images such as icon buttons or linked logos: describe the action or destination, not the picture.
- Images of text: repeat the words in the image, and avoid these except for logos.
- Charts and diagrams: a short alt plus the full data in nearby text or a table.

For search, Google's [image SEO best practices](https://developers.google.com/search/docs/appearance/google-images) call alt text the most important attribute for image metadata and ask for useful, information-rich descriptions in context, without keyword stuffing. Short, descriptive file names such as toronto-spa-treatment-room.webp help too. Our post on [UX writing for websites](https://tcomconsultants.com/blog/ux-writing-for-websites/) covers the same plain-language approach for buttons and labels.

Do not start alt text with "image of" or "picture of". Screen readers already announce that it is an image.


## A repeatable image workflow

Image quality slips when every new upload depends on someone remembering the rules. Build them into your process instead.

1. Resize originals to a sensible maximum width before upload.
2. Let your CMS or build step generate AVIF, WebP and fallback versions at your chosen widths.
3. Output a picture element with srcset, sizes, width and height.
4. Mark below-the-fold images as lazy and leave the hero eager.
5. Require an alt field on upload, with a checkbox for decorative images.
6. Check key pages in PageSpeed Insights after each major content update.

If your pages also carry structured data, point the image properties in your markup at the same optimized files. Our answer on [schema markup for small businesses](https://tcomconsultants.com/answers/schema-markup-for-small-business/) explains where images fit in. Image choices also shape the look of a site, so read [web design trends](https://tcomconsultants.com/blog/web-design-trends/) and [dark mode web design](https://tcomconsultants.com/blog/dark-mode-web-design/) before you commission new photography.


## How Tcom can help

We build image pipelines like this into the sites we run, including spa and wellness sites for more than 30 countries; you can see examples in [our work](https://tcomconsultants.com/work/). If your pages are slow or your alt text is missing, our [website development](https://tcomconsultants.com/services/website-development/) team can audit and fix it. [Get in touch](https://tcomconsultants.com/contact/) and tell us which pages matter most.

## Sources

- An image format for the Web (WebP) (Google for Developers): https://developers.google.com/speed/webp
- Image formats: AVIF (web.dev): https://web.dev/learn/images/avif
- Browser-level image lazy loading for the web (web.dev): https://web.dev/articles/browser-level-image-lazy-loading
- Images Tutorial (W3C Web Accessibility Initiative): https://www.w3.org/WAI/tutorials/images/
- Google image SEO best practices (Google Search Central): https://developers.google.com/search/docs/appearance/google-images

Source: https://tcomconsultants.com/blog/image-optimization-webp/
