Chapter 9: Embedded Content & Images

The alt Attribute – Accessibility Essential

The definitive guide to non-visual image accessibility: WCAG 2.2 Success Criterion 1.1.1, the Accessibility Tree mapping, screen reader behaviors, and the comprehensive alt-text decision tree.

LEARNING OBJECTIVES
  • Understand WCAG 2.2 Success Criterion 1.1.1 (Non-text Content, Level A) and its legal and ethical necessity.
  • Master how assistive technologies (Screen Readers: NVDA, JAWS, VoiceOver) parse the HTML Accessibility Tree (a11y tree) for image elements.
  • Apply the W3C Alt-Text Decision Tree to accurately classify images as informative, functional, decorative, or complex.
  • Differentiate between alt="" (empty/null alt for decorative images) and omitting the alt attribute entirely.
  • Craft contextual, concise, high-value alternative text that communicates intent and function rather than superficial visual minutiae.
🎬 INTERACTIVE VISUAL PIPELINE Core Architecture Simulation
🌐
1. Input
Directives & Tags
⚙️
2. Parse
Tokenizer & AST
🌳
3. Layout
Box Model & Flow
🎨
4. Render
GPU Paint & Composite
PHASE 1: INPUT & DIRECTIVES
Browser receives declarative markup stream, parsing tag tokens and initializing component state.

📖 The Mental Model & Story (Intuitive Foundation)

Imagine walking into a high-end French restaurant where the waiter hands you a printed menu. If you can read the printed text, you immediately see the dish descriptions, wine pairings, and prices. But imagine you are sitting with a companion who has visual impairments. You wouldn't say: "Here is a color image of a ceramic white plate with dimensions 800 by 600 pixels containing brown circular organic material and green leaf garnishes."

Instead, you say: "Pan-seared Atlantic scallops served over truffle pea purée."

You conveyed the essence and meaning of the visual asset, not a raw pixel-by-pixel rendering.

Now, imagine the menu has an ornate gold filigree border printed around every page corner for decorative flair. You wouldn't interrupt your dinner conversation to announce: "Gold floral ornament top-left corner... Gold floral ornament top-right corner..." You completely ignore the decorative border because it conveys zero informational value.

+-------------------------------------------------------------------------------+
|                             IMAGE PURPOSE SPECTRUM                            |
|                                                                               |
|   [DECORATIVE] <---------> [FUNCTIONAL] <---------> [INFORMATIVE] <---------> |
|  Background swirl,        Search magnifying        Chart showing Q3          |
|  abstract divider.        glass icon button.       revenue growth (+18%).    |
|                                                                               |
|  alt="" (Null alt)        alt="Search site"        alt="Bar chart: Q3..."    |
|  (Silenced for a11y)      (Describes action)       (Conveys exact data)      |
+-------------------------------------------------------------------------------+

The alt attribute is not a caption, and it is not a tooltip. It is the programmatic textual substitute for people who cannot see the image, whether due to blindness, low vision, temporary eye injuries, screen reader use, or slow 2G mobile connections where image loading has failed or been disabled.


Technical Deep Dive & Specifications

The Accessibility Tree & Screen Reader Pipeline

Browsers maintain two primary internal tree structures:

  1. The DOM Tree (Document Object Model): Represents all HTML tags and attributes for rendering and scripting.
  2. The Accessibility Tree (a11y Tree): A filtered, semantic representation of the DOM passed directly to OS-level assistive APIs (UI Automation on Windows, NSAccessibility on macOS/iOS, AT-SPI on Linux).
   HTML Markup: <img src="cart.svg" alt="View shopping cart (3 items)">
                            |
                            v
   +-----------------------------------------------------------------+
   | DOM Element: HTMLImageElement                                   |
   +-----------------------------------------------------------------+
                            |
                            v (Computed by Browser Engine)
   +-----------------------------------------------------------------+
   | Accessibility Node                                              |
   | - Role: "image" (or "graphic")                                  |
   | - Accessible Name: "View shopping cart (3 items)"               |
   +-----------------------------------------------------------------+
                            |
                            v
   +-----------------------------------------------------------------+
   | Screen Reader (NVDA / VoiceOver / JAWS) Output:                 |
   | "Graphic, View shopping cart (3 items)"                         |
   +-----------------------------------------------------------------+

The Crucial Difference: alt="" vs. Omitted alt

This is one of the most critical rules in web development:

HTML Syntax Accessibility Tree Role Screen Reader Behavior Use Case
<img src="icon.svg" alt="Search"> Role: image, Name: "Search" Reads: "Graphic, Search" Informative or Functional Image
<img src="bg.svg" alt=""> Role: none / presentation Completely ignored (silent) Purely Decorative Image
<img src="photo.jpg"> (Missing alt) Role: image, Name: photo.jpg Reads raw filename or URL! 🚨 Severe Accessibility Violation

[!CAUTION] When the alt attribute is omitted entirely, the browser is forced to guess. Screen readers will often announce: "Graphic, https slash slash cdn dot company dot com slash assets slash upload underscore 77291a dot jpeg". This creates a frustrating, hostile user experience for blind users.


The W3C Alt-Text Decision Tree

                                  [ Does the image exist? ]
                                             |
                                             v
                       [ Does the image convey critical information? ]
                                     /               \
                                   YES                NO
                                   /                    \
  [ Is the image inside an <a> or <button>? ]     [ Is it purely decorative? ]
          /                     \                          /            \
        YES                      NO                      YES             NO
        /                         \                      /                 \
 [ FUNCTIONAL ]            [ INFORMATIVE ]         [ DECORATIVE ]      [ COMPLEX CHART ]
 Describe action:          Describe meaning:       Use null alt:       Use short alt +
 alt="Print invoice"       alt="Smiling team"      alt=""              detailed text fallback

The 5 Functional Categories of Alt-Text

  1. Informative Images: Images that visually add new concepts, instructions, or context to the page.
    • Example: An infographic illustrating photosynthesis.
    • Alt rule: Summarize the visual finding concisely.
  2. Decorative Images: Stylistic flourishes, borders, background gradients, or images already described verbatim in adjacent text.
    • Example: A decorative swoosh line under a heading.
    • Alt rule: Use alt="" (empty string) to remove it from the Accessibility Tree.
  3. Functional Images: Images that act as interactive triggers (inside <a> or <button>).
    • Example: A printer icon that prints the document.
    • Alt rule: Describe the action (alt="Print document"), NOT the appearance (alt="Black printer icon").
  4. Images of Text: Visual graphics containing rendered typographic text (logos, promotional banners).
    • Example: A company logo banner reading "Cyber Monday 50% Off".
    • Alt rule: Transcribe the exact words contained within the image (alt="Cyber Monday 50% Off").
  5. Complex Images: Data charts, architectural diagrams, schematics, and maps.
    • Example: A multi-line quarterly sales chart.
    • Alt rule: Provide a high-level summary in alt, and provide full data in an adjacent HTML <table> or <figcaption>.

💻 Interactive Code Playground

Starter Code

Line-by-Line Code Breakdown

  • Line 46 (alt="A scientist in a cleanroom..."): Provides a vivid, contextual description of the visual scene.
  • Line 58 (<img src="..." alt="" width="20" height="20">): Inside the <button>, the text label "Print Invoice" is already present in the DOM (<span>Print Invoice</span>). Giving the printer icon an alt="Print" would cause a screen reader to announce: "Graphic Print, Print Invoice button". Using alt="" silences the decorative icon, ensuring the screen reader announces only "Print Invoice, button".
  • Line 72 (alt="" role="presentation"): Explicitly removes the horizontal divider graphic from the Accessibility Tree.

Expected Browser Render Output


SYS: ACTIVE
HULL: 98%
CORE: STABLE
NET: ONLINE
HTML STARSHIP CODE TERMINAL playground.html
LIVE RENDER & DIAGNOSTICS CORE TEMP: 45°C
INSPECTING DOM: VALID
TAGS: SCANNING...
+-------------------------------------------------------------+
| WCAG 2.2 Alt-Text Implementation Showcase                   |
|                                                             |
| [1. Informative Image]                                      |
| +---------------------------------------------------------+ |
| | [SCIENTIST IN CLEANROOM EXAMINING SILICON WAFER]        | |
| +---------------------------------------------------------+ |
| Semiconductor manufacturing cleanroom operations.           |
|                                                             |
| [2. Functional Image (Button)]                              |
| [ 🖨️  Print Invoice ]                                      |
|                                                             |
| [3. Decorative Flourish]                                    |
| - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| Section separator ignored by screen readers.                |
+-------------------------------------------------------------+

🏋️ Hands-On Exercise

🎯 The Challenge: Fix the Inaccessible Enterprise Dashboard

Instructions: Audit and fix the following broken corporate markup snippet:

  1. Item 1: An image showing the CEO portrait currently has no alt attribute. Add an informative description.
  2. Item 2: A standalone navigation icon button linking to the user settings currently has alt="blue cog icon picture". Refactor it to convey its true functional action.
  3. Item 3: An ornamental abstract background wave image currently has alt="abstract gradient vector". Fix it so screen readers ignore it completely.
  4. Item 4: A bar chart image shows 2026 Q1 sales breakdown. Add a concise alt summary and include a visually hidden or semantic fallback data table.

🏁 Starter Code Sandbox

SYS: ACTIVE
HULL: 98%
CORE: STABLE
NET: ONLINE
STARTER CODE SANDBOX exercise.html
LIVE RENDER & DIAGNOSTICS CORE TEMP: 45°C
INSPECTING DOM: VALID
TAGS: SCANNING...

⚠️ Common Pitfalls

  1. Redundant "Image of..." Prefixes: Never write alt="Image of a red sports car". Screen readers already announce the element's role ("Graphic, red sports car"). Writing "image of" causes clumsy output: "Graphic, image of a red sports car".
  2. Using Filenames as Alt Text: Writing alt="IMG_59281.JPG" or alt="banner-v2-final.png" is useless and harms accessibility audits.
  3. Copy-Pasting Captions into Alt: If an image is immediately followed by a visible caption <p>The Golden Gate Bridge at dusk</p>, writing alt="The Golden Gate Bridge at dusk" forces screen reader users to hear the identical sentence twice in a row. Use alt="" or provide distinct, complementary detail.
  4. Omitting alt on Interactive Links: Placing an <img src="logo.png"> inside <a href="/"> without alt causes screen readers to read the link's URL path: "Link slash". Always use alt="Acme Corp Home".

💡 Pro Tips

  1. Context Determines Content: The exact same photograph of coffee beans requires different alt text depending on context:
    • On a coffee shop homepage: alt="Freshly roasted Ethiopian dark roast beans".
    • On an article about agricultural fungus: alt="Coffee bean exhibiting severe rust discoloration along the center seam".
    • In a website footer background pattern: alt="".
  2. Automated CI/CD A11y Linting: Integrate tools like @axe-core/cli or ESLint jsx-a11y/alt-text into your deployment pipeline to block builds where <img> tags lack alt attributes.
  3. Search Engine Optimization (SEO): Google Image Search and Googlebot crawl alt text to understand image context. Accurate, keyword-rich (but not keyword-stuffed) alt text directly improves Google Image search indexing.

📌 Key Takeaways

  • WCAG 2.2 SC 1.1.1 mandates text alternatives for all non-text content.
  • alt="" (null alt) removes decorative images from the Accessibility Tree while keeping them visual for sighted users.
  • Omitting the alt attribute completely causes screen readers to read the raw image URL or filename.
  • For functional images inside links or buttons, the alt text must describe the action or destination, not the physical visual icon.
  • Avoid phrases like "picture of" or "image of" in alt text; the screen reader automatically announces the graphic role.
  • --
⭐ LEARN: HTML 🌟 ⚔️ QUIZ BATTLE ARENA // ACTIVE
3x
STREAK!
BONUS ACTIVE
COMBO
? Question 1 / 3

What does a screen reader announce when it encounters an image written as <img src="divider.png" alt="">?

Question 1 / 3 Topic: HTML Fundamentals
00:45 REMAINING
XP REWARD
+250 XP
3x
STREAK!
BONUS ACTIVE
COMBO
? Question 2 / 3

You have a search button written as <button type="submit"><img src="search.svg" alt="Search"></button>. Is this accessible?

Question 2 / 3 Topic: HTML Fundamentals
00:45 REMAINING
XP REWARD
+250 XP
3x
STREAK!
BONUS ACTIVE
COMBO
? Question 3 / 3

Which of the following is considered an accessibility anti-pattern?

Question 3 / 3 Topic: HTML Fundamentals
00:45 REMAINING
XP REWARD
+250 XP