Images: the area where three topics hang together
AccessibilityImages are the only area of a website where accessibility, loading time and search engine optimisation hang on the same adjusting screws.
6 min read
By Timo Wessels Published
Images are the area of a website where accessibility, load time and search engines hang on the same screws. Five things count:
- The alt text, the description for people who cannot see the image.
- The file size.
- The format.
- Width and height in the HTML.
- Whether an image loads delayed or at once.
The most important points first:
- Every image gets an alt text. A purely decorative one gets an empty one.
- The top large image of a page must never be loaded with a delay.
- Width and height belong on every image, so the page does not jump while loading.
The alt text
The alt text sits in the <img> tag and is, besides the file path, the only mandatory element (Rheinwerk, Barrierefreie Webseiten, ch. 7.3). A screen reader, a program that reads the page aloud, outputs it in place of the image. The guiding rule: as short as possible, as long as necessary.
Two questions decide for every image:
- Is it just decoration, or do you need it to understand the page?
- If you need it: what information does it carry?
Decorative images get an empty alt attribute: alt="". This matters: empty, but present. If the attribute is missing altogether, a screen reader often reads out the file name. Only the empty one says “there is nothing to read out here”. The W3C says the same for images whose text also stands next to them as real text.
Images as a link or button do not describe the image but the function. alt="To the contact form" is right, alt="Envelope icon" is not. The W3C calls these functional images: the text says which action is triggered.
Length: 100 to 125 characters are a good starting point (Rheinwerk, Barrierefreie Webseiten, ch. 7.3). Do not stuff in search terms. That helps neither accessibility nor ranking.
File size and format
On most websites images make up the largest part of the data transferred. My rules of thumb from practice:
- A hero image, the large image at the very top, should not exceed 150 KB; the absolute upper limit is about 200 KB.
- Images in the text should stay under 100 KB after conversion to a modern format.
Format: AVIF is a modern image format. WordPress has supported it since version 6.5. According to WordPress, AVIF files can be up to 50 percent smaller than JPEG at the same quality. The server must support AVIF, otherwise the upload does not work.
The right size: An image should never be delivered larger than it is shown on the screen. Anything beyond that wastes data and slows the page. Lighthouse reports this.
Width and height in the HTML
Give every image a width and a height. The browser then reserves the space before loading, and the text below does not jump. This jumping is exactly what Google measures as Cumulative Layout Shift, CLS for short. Alternatively it works with the CSS property aspect-ratio.
Delayed loading and the trap at the top image
Delayed loading is called lazy loading. The image is loaded only when it is about to come into view. That saves data for images further down.
For the top large image it is a mistake. It is usually the element whose load time Google measures as Largest Contentful Paint (LCP): the time until the largest visible element is done. Delayed loading makes this most important measurement worse. web.dev says: never lazy-load the LCP image.
For this one image you set fetchpriority="high" instead. That tells the browser: this one first. web.dev advises doing this for only one or two images, otherwise it stops helping.
WordPress has set fetchpriority="high" automatically since version 6.3 on the image it considers the largest. For images that sit inside a component, in my experience that often does not take effect. Then you have to set it yourself.
How to check it yourself
Alt texts: In the WordPress media library you see the alt text field on every image. Once set, the text is inserted everywhere the image is used. Empty fields on images that matter for the content are the finding.
File size: Open the developer tools with F12, choose the “Network” tab, filter on “Img” and reload the page. You see every image file with its size. Sort descending. The top three are your job.
Overall picture: PageSpeed Insights shows you with “Efficiently encode images” and “Properly size images” which files are worth the work.
Lazy loading: Open the page source and search for loading="lazy". If it sits on the first large image of the page, that is the mistake.
What you can do if it is missing
1. Fill in the alt texts in the media library, once there instead of at every use. Describe what is shown and why the image is there. For decorative images, set an empty alt attribute on purpose.
2. Convert images to AVIF or WebP. A plugin or a CDN optimiser can do this on upload or on delivery.
3. Name files sensibly before uploading: larch-garden-house-grey.webp instead of IMG_0023.JPG. Three to six words, hyphens instead of underscores, lower case, no umlauts. This is my rule.
4. Put width and height on every <img>. In Etch and ACSS the image components do this.
5. Treat the hero image as a special case: no lazy loading, fetchpriority="high" instead.
Sources
- W3C, An alt Decision Tree — when an alt text describes and when it stays empty, including text in the image that also stands next to it as real text: w3.org(external site: w3.org)
- W3C, Functional Images — for images in links and buttons the alt text names the action triggered: w3.org(external site: w3.org)
- web.dev, Optimize Largest Contentful Paint — never lazy-load the LCP image,
fetchpriority="high"for one or two images: web.dev(external site: web.dev) - web.dev, Optimize Cumulative Layout Shift — width and height on images or
aspect-ratio: web.dev(external site: web.dev) - WordPress Core Team, Image performance enhancements in WordPress 6.3 —
fetchpriority="high"is set automatically: make.wordpress.org(external site: make.wordpress.org) - WordPress Core Team, WordPress 6.5 adds AVIF support — AVIF up to 50 percent smaller than JPEG, hosting must support AVIF: make.wordpress.org(external site: make.wordpress.org)
- Chrome for Developers, Properly size images — never serve images larger than shown: developer.chrome.com(external site: developer.chrome.com)
- Rheinwerk, Barrierefreie Webseiten, ch. 7.3 — alt text as a mandatory element, the guiding rule, the two questions per image, 100 to 125 characters as a starting point, maintaining alt text centrally in the media library.
- Own testing practice — the rules of thumb of 150, 200 and 100 KB, the naming of files, the hero image inside components.