Design, UX & content

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.

By Tcom Consultants · Updated · 5 min read · 5 sources

Agent network illustration for Image optimization: WebP, AVIF, sizes and alt text

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 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 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 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.

FormatBest forWatch out for
AVIFPhotos and large hero images where every kilobyte countsSlower to encode; always provide a fallback
WebPGeneral photos, product shots, transparent graphicsVery old browsers need a JPEG or PNG fallback
JPEGFallback for photos, email imagesNo transparency; larger than modern formats
PNGFallback for screenshots and graphics with sharp edgesLarge files for photographic content
SVGLogos, icons, simple illustrationsNot 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 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 is read aloud by screen readers and shown when an image fails to load. The W3C images tutorial 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 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 covers the same plain-language approach for buttons and labels.

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 explains where images fit in. Image choices also shape the look of a site, so read web design trends and 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. If your pages are slow or your alt text is missing, our website development team can audit and fix it. Get in touch and tell us which pages matter most.

Questions

Should I convert every image on my site to AVIF?

Convert large photos first, since that is where the savings are biggest. Keep WebP and JPEG or PNG versions as fallbacks so every browser can still show the image.

Does alt text affect Google rankings?

Google uses alt text to understand images and shows images in Google Images partly based on it. Write it for people first; useful descriptions serve both.

What file size should a hero image be?

There is no single correct number because it depends on dimensions and content. Aim for the smallest AVIF or WebP file that still looks sharp at the largest size it displays, and test on a mid-range phone.

Can I use SVG for photos?

No. SVG is a vector format meant for logos, icons and simple illustrations. Photos belong in AVIF, WebP or JPEG.

Sources

  1. An image format for the Web (WebP) Google for Developers
  2. Image formats: AVIF web.dev
  3. Browser-level image lazy loading for the web web.dev
  4. Images Tutorial W3C Web Accessibility Initiative
  5. Google image SEO best practices Google Search Central

Sources checked 23 November 2026.