
Writing Image Alt Text for Accessibility and SEO: Best Practices & Code Examples
The Dual Role of Alternative Text
Image alt text serves two critical purposes on the modern web:
- Assistive Accessibility (WCAG 2.1 AA): Screen readers articulate alt text to visually impaired visitors so they understand the context and purpose of the graphic.
- Search Engine Discovery: Web crawlers (Googlebot) rely on alt attributes to index images accurately and understand page content relevance.
1. The Decision Hierarchy for Image Alt Text
Not every image requires descriptive text. Use this flow to determine the correct attribute value:
- Informative Images: Photos that illustrate key article concepts or products require succinct, descriptive copy.
- Functional Images: Icons acting as buttons or links (e.g., search magnifying glass, social icons) must describe the action rather than the visual:
<!-- Incorrect --> <button><img src="magnifier.svg" alt="Magnifying glass icon"></button> <!-- Correct --> <button><img src="magnifier.svg" alt="Search product catalog"></button> - Purely Decorative Images: Background gradients, decorative dividers, and abstract shapes should feature an empty alt tag (
alt="") so screen readers skip them cleanly:<img src="curved-separator.svg" alt="" role="presentation">
2. Avoiding Common Alt Text Pitfalls
- Keyword Stuffing: Never repeat your target keyword phrase mechanically. Search engines penalize unnatural stuffing, and it destroys user experience for screen reader users.
- Redundant Prefixes: Never start with "Picture of" or "Image of". Screen readers already announce the element as an image before reading the alt description.
- Missing File Dimensions: Always pair alt text with explicit
widthandheightattributes to prevent layout shifts (CLS).
Conclusion
High-quality alt text bridges accessibility and technical SEO with minimal engineering overhead. For comprehensive accessibility and technical SEO audits, review my services or get in touch.



