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
alttext for standalone image links versus decorativealt=""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.
๐ 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 →</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 →</span> |
| </a> |
+-----------------------------------------------------------------------------------+
๐ป 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")
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:
- The banner image link.
- The headline link.
- The "Read Article" text button link.
This creates 3 separate tab stops and triple screen reader noise.
Your Instructions:
- Consolidate all three elements into a single accessible
<a href="/articles/future-of-web">compound card. - Mark the thumbnail image as decorative (
alt=""andaria-hidden="true") to prevent double announcement. - Include an external standalone social sharing icon link outside the card that uses proper functional alt text.
๐ Starter Code Sandbox
โ ๏ธ Common Pitfalls
- Omitting
altAttribute Entirely on Linked Images: Writing<a href="/"><img src="logo.png"></a>with noaltattribute 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. - 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 bealt="View Shopping Cart". - Legacy Blue Borders on Linked Images: Older browsers rendered a thick blue border around
<img>elements inside<a>. Modern CSS resets should includeimg { border-style: none; }.
๐ก Pro Tips
- 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; } - Explicit Image Dimensions: Always declare
widthandheightattributes 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 wherealttext provides the link's accessible name. - For standalone image links, the
alttext must describe the destination, not the visual graphic. - For compound card links, mark the thumbnail as decorative (
alt=""andaria-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
altattribute on linked images, as this causes screen readers to vocalize raw file paths. - --