๐ŸŒ Chapter 8: Links & Navigation

Image Links & Accessible Name Computation

Mastering the art of wrapping `<img>` inside `<a>`, calculating accessible names via the W3C AccName 1.2 algorithm, and designing high-performance compound cards.

LEARNING OBJECTIVES โŒต
  • Understand how wrapping an <img> in an <a> transforms the image's role into a functional hyperlink.
  • Trace the W3C Accessible Name and Description Computation (AccName 1.2) waterfall for linked graphics.
  • Write functional alt text for standalone image links versus decorative alt="" inside compound card links.
  • Eliminate the "Double Announcement" anti-pattern in multi-link teaser cards.
  • Implement responsive, accessible compound card patterns using the HTML5 transparent content model.
๐ŸŽฌ 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 through a museum of paintings. Each painting has a small plaque next to it describing what the artwork depicts: "Oil painting of a sunset over the Atlantic Ocean."

Now imagine that touching the painting activates a hidden portal that transports you directly to the museum's gift shop. If the plaque still only says "Oil painting of a sunset", you have no idea where touching it will take you. The plaque's description must change from describing the picture to describing the portal's destination: "Touch to Visit the Gift Shop."

                              IMAGE CONTEXT DUALITY
                                        |
           +----------------------------+----------------------------+
           |                                                         |
   STANDALONE STATIC IMAGE                                  IMAGE WRAPPED IN ANCHOR
     <img src="logo.png">                               <a href="/"><img src="logo.png"></a>
           |                                                         |
+--------------------------+                               +--------------------------+
| Descriptive Alt Text     |                               | Functional Alt Text      |
| alt="Acme Corp Logo"     |                               | alt="Acme Corp - Home"   |
+--------------------------+                               +--------------------------+

When an image is wrapped inside an anchor tag, it is no longer just visual decoration; it becomes an interactive control. The image's alt text becomes the Accessible Name of the entire hyperlink in the browser's accessibility tree.


Technical Deep Dive & Specifications

The W3C AccName 1.2 Algorithm Waterfall

When an assistive technology (such as VoiceOver, NVDA, or JAWS) inspects an anchor tag wrapping an image, it computes the link's Accessible Name according to the W3C AccName 1.2 Specification:

                  ACCNAME 1.2 COMPUTATION WATERFALL FOR <a>
                                      |
                      Does <a> have aria-labelledby?
                                     / \
                                   YES  NO
                                   /     \
                Use referenced text       Does <a> have aria-label?
                                                    / \
                                                  YES  NO
                                                  /     \
                               Use aria-label text       Does <a> contain inner text?
                                                                   / \
                                                                 YES  NO
                                                                 /     \
                               Combine inner text + <img> alt           Use <img> alt attribute
                                                                                   / \
                                                                                 YES  NO
                                                                                 /     \
                                                             Use alt text value       โŒ UNLABELED LINK
                                                                                      (Reads raw href URL)
+----------------------------------------------------------------------------------------------------+
| Pattern Code                                       | Computed Accessible Name | Accessibility Verdict|
+----------------------------------------------------------------------------------------------------+
| <a href="/"><img src="logo.svg" alt="Home"></a>    | "Home, link"             | โœ… Perfect           |
| <a href="/"><img src="logo.svg" alt=""></a>        | (Empty / URL string)     | โŒ Critical Failure  |
| <a href="/" aria-label="Acme Home"><img ...></a>   | "Acme Home, link"        | โœ… Excellent         |
| <a href="/post"><img alt="Robot"><h3>AI</h3></a>   | "Robot AI, link"         | โš ๏ธ Stutter / Clutter |
+----------------------------------------------------------------------------------------------------+

Standalone Image Links vs. Compound Card Links

1. Standalone Graphic Links (e.g. Logos, Social Icons)

When an anchor contains only an image (no text headings or spans), the <img> MUST have functional alt text indicating where the link navigates:

<!-- โœ… CORRECT: Alt text describes the destination, NOT the visual artwork -->
<a href="https://twitter.com/acmecorp" target="_blank" rel="noopener noreferrer">
  <img src="twitter-icon.svg" alt="Follow Acme Corp on Twitter">
</a>

2. Compound Card Links (Image + Heading + Paragraph)

When an anchor wraps both an image thumbnail and descriptive text (like an <h3>), giving the image descriptive alt text causes screen readers to repeat themselves:

<!-- โŒ NOISY ANTI-PATTERN: Double announcement -->
<a href="/articles/html5">
  <img src="html5.png" alt="HTML5 Logo">
  <h3>HTML5 Logo: The Complete Guide</h3>
</a>
<!-- Screen Reader announces: "Link: HTML5 Logo HTML5 Logo: The Complete Guide" -->
<!-- โœ… PRODUCTION PATTERN: Empty alt="" on decorative thumbnail inside compound link -->
<a href="/articles/html5" class="compound-card">
  <img src="html5.png" alt="" aria-hidden="true">
  <h3>HTML5: The Complete Guide</h3>
</a>
<!-- Screen Reader announces cleanly: "Link: HTML5: The Complete Guide" -->

Eliminating the "Multi-Link Card" Anti-Pattern

Junior developers often build blog preview cards with 3 independent links pointing to the exact same URL:

+-----------------------------------------------------------------------------------+
| โŒ MULTI-LINK CARD ANTI-PATTERN (3 Tab Stops for 1 Article)                        |
|                                                                                   |
|  [ Link 1: <a href="/post"><img alt="Thumb"></a> ]                                |
|  [ Link 2: <a href="/post"><h3>Post Title</h3></a> ]                              |
|  [ Link 3: <a href="/post">Read More &rarr;</a> ]                                 |
+-----------------------------------------------------------------------------------+

This forces keyboard users to press Tab 3 times per article. In a feed of 20 articles, the user must press Tab 60 times to navigate the page!

The Senior Solution: Single Transparent Compound Card

+-----------------------------------------------------------------------------------+
| โœ… SINGLE COMPOUND CARD (1 Clean Tab Stop)                                        |
|                                                                                   |
|  <a href="/post" class="card-link">                                               |
|    <img src="thumb.webp" alt="" aria-hidden="true">                                |
|    <h3>Post Title</h3>                                                            |
|    <p>Teaser snippet...</p>                                                       |
|    <span class="cta">Read More &rarr;</span>                                      |
|  </a>                                                                             |
+-----------------------------------------------------------------------------------+

SYS: ACTIVE
HULL: 98%
CORE: STABLE
NET: ONLINE
HTML STARSHIP CODE TERMINAL example.html
LIVE RENDER & DIAGNOSTICS CORE TEMP: 45ยฐC
INSPECTING DOM: VALID
TAGS: SCANNING...

๐Ÿ’ป Interactive Code Playground

Starter Code

Line-by-Line Code Breakdown

  • Line 18โ€“33 (.product-card-link): Transforms the entire anchor into a flexbox container with interactive hover/focus states.
  • Line 34โ€“37 (:focus-visible): Guarantees a bold 3px focus ring around the entire compound card when navigated via the keyboard.
  • Line 77โ€“81 (<img ... alt="" aria-hidden="true">): Marks the thumbnail as purely decorative within the context of the link, because the <h2> immediately following supplies the complete, descriptive accessible name.
  • Line 83โ€“86 (<div class="card-body">): Encapsulates the category, title, and price within the single transparent anchor.

Expected Browser Render Output

(Computed Accessibility Tree Name: "Hardware Apex Pro Wireless Mechanical Keyboard $199.99, link")


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...
Compound Image Card Architecture
Single focus stop, seamless AccName calculation, and zero double-announcements:

+-------------------------------------------+
| [ High-Res Keyboard Photography Image ]   |
|                                           |
+-------------------------------------------+
| HARDWARE                                  |
| Apex Pro Wireless Mechanical Keyboard     |
| $199.99                                   |
+-------------------------------------------+

๐Ÿ‹๏ธ Hands-On Exercise

๐ŸŽฏ The Challenge: Refactor the Noisy Multi-Link Blog Feed

You are refactoring a legacy blog feed. Currently, each article card contains three separate links pointing to /articles/future-of-web:

  1. The banner image link.
  2. The headline link.
  3. The "Read Article" text button link.

This creates 3 separate tab stops and triple screen reader noise.

Your Instructions:

  1. Consolidate all three elements into a single accessible <a href="/articles/future-of-web"> compound card.
  2. Mark the thumbnail image as decorative (alt="" and aria-hidden="true") to prevent double announcement.
  3. Include an external standalone social sharing icon link outside the card that uses proper functional alt text.

๐Ÿ 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. Omitting alt Attribute Entirely on Linked Images: Writing <a href="/"><img src="logo.png"></a> with no alt attribute forces the screen reader to announce the raw URL string (e.g. "Link: slash assets slash logo dot png"), creating a severe WCAG Level A violation.
  2. Describing the Visual Asset Instead of the Action on Standalone Links: Writing <a href="/cart"><img src="cart.svg" alt="Shopping Cart Graphic"></a>. The functional alt text should be alt="View Shopping Cart".
  3. Legacy Blue Borders on Linked Images: Older browsers rendered a thick blue border around <img> elements inside <a>. Modern CSS resets should include img { border-style: none; }.

๐Ÿ’ก Pro Tips

  1. The Stretched-Link Technique: If your card contains complex layout interactions, you can place a standard text link inside the heading and expand its clickable hit area across the entire parent card using CSS:
    .card { position: relative; }
    .card-title a::after {
      content: "";
      position: absolute;
      inset: 0;
    }
    
  2. Explicit Image Dimensions: Always declare width and height attributes on linked images to eliminate Cumulative Layout Shift (CLS) during page loading.

๐Ÿ“Œ Key Takeaways

  • An <img> wrapped in an <a> acts as an interactive control where alt text provides the link's accessible name.
  • For standalone image links, the alt text must describe the destination, not the visual graphic.
  • For compound card links, mark the thumbnail as decorative (alt="" and aria-hidden="true") to prevent double announcements.
  • Replace multi-link cards (image link + heading link + button link) with a single transparent compound anchor.
  • Never omit the alt attribute on linked images, as this causes screen readers to vocalize raw file paths.
  • --
โญ LEARN: HTML ๐ŸŒŸ โš”๏ธ QUIZ BATTLE ARENA // ACTIVE
3x
STREAK!
BONUS ACTIVE
COMBO
? Question 1 / 3

What does a screen reader announce when encountering <a href="/home"><img src="brand.svg"></a> (where the alt attribute is completely missing)?

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

In a compound card containing both a thumbnail image and an <h3>Article Title</h3> inside one <a> element, what is the best practice for the image's alt attribute?

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

What is the computed accessible name for the element <a href="/search" aria-label="Search Catalog"><img src="magnifier.svg" alt="Magnifying Glass"></a>?

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