brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: an empty alt in HTML tells screen readers to skip a decorative image

Html
~/tips/tip-html-empty-alt-decorative

cat ~/tips/tip-html-empty-alt-decorative.md

Stop screen readers from announcing file names of pictures that mean nothing.

Not every image needs a description. A swirl between two sections or an icon next to a word that already says it all only adds noise when read aloud.

Give such an image an empty alt:

<img src="swirl.svg" alt="">

<a href="/downloads">
  <img src="arrow.png" alt=""> Downloads
</a>

A screen reader then passes over it. Leaving the attribute out entirely is different: some screen readers will read the file name instead, and hearing IMG underscore 4032 helps nobody.

The question I ask is what would be lost if the picture disappeared. Nothing means empty alt. If it carries information, describe that information. And if the image is the only content of a link or button, it is never decorative: the alt should say where the link goes or what the button does, such as alt="Search" on a magnifying glass.

Write it with nothing between the quotes, not even a space. Purely visual flourishes can often live in CSS as a background instead, which keeps the markup clean. Automated checkers accept any empty alt, so they cannot tell you whether you chose right.

Further reading: W3C WAI: decorative images

More Html tips import { format } from "dates"; width="640" height="360" poster="demo.jpg"> The HTML optgroup element puts headings inside a long dropdown srclang="en" label="English" default> An HTML noindex meta tag keeps one page out of search results All Html tips (14) All topics

Link