Accessibility (a) Rules - 3
Images
It's not just about adding alt text to an image; it's much more than that.
Decorative images
If an image doesn't add additional context or information (decorative image) that allows the user to better understand the context then it should be hidden from assistive technology (AT), such as a screen reader.
-
Use any of these methods to hide images from AT:
- An empty or null text alternative (alt)
- Applying ARIA
- Add the image as a CSS background
<!-- All of these choices lead to the same result. --> <img src=".../Ladybug.jpg" role="presentation"> <img src=".../Ladybug.jpg" role="none"> <img src=".../Ladybug.jpg" aria-hidden="true">
- When in doubt, add descriptions to images.
Empty or null alt
- Do not set the image alt attribute to "" unless the image is purely decorative.
Attribute | Example | Screen Reader Behavior | Use Case |
---|---|---|---|
alt="" (Empty) | ![]() |
Ignores the image completely | Decorative or non-informative images |
Missing alt | ![]() |
May read the filename/URL | Not recommended; implies negligence |
Informative images
If an image conveys a concept, idea, or emotion you should include programmatic alternative text describing the purpose of the image.
Add a highly detailed description of the image wherever possible.
e.g.
<img src=".../Ladybug_Swarm.jpg" alt="A swarm of red ladybugs is resting on the leaves of my prize rose bush.">
If the image is an (inline), add role="img".
Since elements do not support the alt attribute, use alternative coding methods to provide a description.
Method | Use Case | Pros | Cons |
---|---|---|---|
Short, brief descriptions | Simple, widely supported | Limited in length | |
aria-label | Brief descriptions | Quick, inline | Best for short text |
aria-labelledby | Complex descriptions using |
Comprehensive, flexible | More verbose |
Visible description in a figure context | Visible and accessible | Not ideal for all SVGs |
Functional images
Any image with a functional purpose (e.g., a logo that links to the home page, a magnifying glass icon used as a search button) should include appropriate alt text.
Alt text should describe the image’s action, not its visual aspects.
If the image is both informative and actionable you can add alternative descriptions to each element—but it is not a requirement. e.g.
<!-- All of these choices lead to the same result. --> <img src=".../Ladybug.jpg" role="presentation"> <img src=".../Ladybug.jpg" role="none"> <img src=".../Ladybug.jpg" aria-hidden="true">
Complex images
If an image requires more explanation than a decorative, informational, or functional image include infographics, maps, graphs/charts, and complex illustrations use any of these methods to add alternative descriptions
Link out to a resource or provide a jump link to a longer explanation later on the page. e.g.
<img src=".../Ladybug_Swarm.jpg" alt="A swarm of red ladybugs is resting on the leaves of my prize rose bush.">
- Append the aria-describedby attribute to the
element then link the image to an ID containing a longer description. e.g.
<div title="Navigate to the homepage"> <a href="/"> <img src=".../Ladybug_Logo.png" alt="Lovely Ladybugs for your Lawn"/> </a> </div>
Alternative text best practices
Advised to cap alternative text to 150 characters or less to avoid reader fatigue.
Avoid using words like "image of" or "photo of" in the description, as the screen reader will identify these file types.
When naming images, be as consistent and accurate as possible. Image names are a fallback when the alternative text is missing or ignored.
Avoid using non-alpha characters (for example, #, 9, &)
Use dashes between words rather than underscores in image names or alternative text.
Use proper punctuation whenever possible. Without it, the image descriptions will sound like one long, never-ending, run-on sentence.
Write alternative text like a human and not a robot. Keyword stuffing does not benefit anyone—people using screen readers will be annoyed, and search engine algorithms will penalize them.
The above is the detailed content of Accessibility (a) Rules - 3. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Frequently Asked Questions and Solutions for Front-end Thermal Paper Ticket Printing In Front-end Development, Ticket Printing is a common requirement. However, many developers are implementing...

JavaScript is the cornerstone of modern web development, and its main functions include event-driven programming, dynamic content generation and asynchronous programming. 1) Event-driven programming allows web pages to change dynamically according to user operations. 2) Dynamic content generation allows page content to be adjusted according to conditions. 3) Asynchronous programming ensures that the user interface is not blocked. JavaScript is widely used in web interaction, single-page application and server-side development, greatly improving the flexibility of user experience and cross-platform development.

There is no absolute salary for Python and JavaScript developers, depending on skills and industry needs. 1. Python may be paid more in data science and machine learning. 2. JavaScript has great demand in front-end and full-stack development, and its salary is also considerable. 3. Influencing factors include experience, geographical location, company size and specific skills.

Learning JavaScript is not difficult, but it is challenging. 1) Understand basic concepts such as variables, data types, functions, etc. 2) Master asynchronous programming and implement it through event loops. 3) Use DOM operations and Promise to handle asynchronous requests. 4) Avoid common mistakes and use debugging techniques. 5) Optimize performance and follow best practices.

Discussion on the realization of parallax scrolling and element animation effects in this article will explore how to achieve similar to Shiseido official website (https://www.shiseido.co.jp/sb/wonderland/)...

The latest trends in JavaScript include the rise of TypeScript, the popularity of modern frameworks and libraries, and the application of WebAssembly. Future prospects cover more powerful type systems, the development of server-side JavaScript, the expansion of artificial intelligence and machine learning, and the potential of IoT and edge computing.

How to merge array elements with the same ID into one object in JavaScript? When processing data, we often encounter the need to have the same ID...

In-depth discussion of the root causes of the difference in console.log output. This article will analyze the differences in the output results of console.log function in a piece of code and explain the reasons behind it. �...
