Accessible Links

How to handle external links and file downloads with clear accessibility indicators.

beginner
2.4.4 Link Purpose (In Context) (Level A)4.1.2 Name, Role, Value (Level A)
โŒ

The Bad (Inaccessible)

<a href="report.pdf" target="_blank">Download Report</a>
โœ…

Accessibility-Ready Code

<!-- 1. Download Link (PDF) -->
<a href="report.pdf" download target="_blank" rel="noopener noreferrer" class="accessible-link">
  Download Annual Report
  <span class="sr-only">(PDF, 2.4MB, opens in new window)</span>
  <svg class="icon" aria-hidden="true" viewBox="0 0 24 24" width="16" height="16">
    <path d="M14,3V5H17.59L7.76,14.83L9.17,16.24L19,6.41V10H21V3M19,19H5V5H12V3H5C3.89,3 3,3.9 3,5V19A2,2 0 0,0 5,21H19A2,2 0 0,0 21,19V12H19V19Z" />
  </svg>
</a>

<!-- 2. External Link (opens in new window) -->
<a href="https://example.com" target="_blank" rel="noopener noreferrer" class="accessible-link">
  Visit Partner Site
  <span class="sr-only">(opens in new window)</span>
  <svg class="icon" aria-hidden="true" viewBox="0 0 24 24" width="16" height="16">
    <path d="M14,3V5H17.59L7.76,14.83L9.17,16.24L19,6.41V10H21V3M19,19H5V5H12V3H5C3.89,3 3,3.9 3,5V19A2,2 0 0,0 5,21H19A2,2 0 0,0 21,19V12H19V19Z" />
  </svg>
</a>

<!-- 3. Internal Link (Standard) -->
<a href="/about" class="accessible-link">
  About Us
</a>

The Standard

When a link opens in a new window or leads to a file download (like a PDF), itโ€™s critical to inform the user before they click. Unexpected context changes can be disorienting, especially for users with cognitive disabilities or those using screen readers.

WCAG Criteria

  • 2.4.4 Link Purpose: The purpose of each link can be determined from the link text alone.
  • 4.1.2 Name, Role, Value: States and properties are programmatically determinable.

โŒ The Bad (Inaccessible)

Whatโ€™s Wrong?

  1. Unexpected Behavior: Users arenโ€™t warned that a new tab will open.
  2. Missing File Info: No indication that the link downloads a large file.
  3. Security Risk: Missing rel="noopener" can lead to performance and security issues in older browsers.

โœ… The Good (Accessibility-Ready Code)

Why This Works

  1. Clear Context: Hidden text (.sr-only) provides specific details to screen reader users without cluttering the UI.
  2. Visual Cues: An icon indicates an external or new-window link for sighted users.
  3. Best Practices: Includes rel="noopener noreferrer" for security and follows modern link standards.

Accessibility Checklist

  • Use target="_blank" only when necessary (e.g., to avoid breaking a flow).
  • Provide a visual icon indicating an external link or new window.
  • Incorporate hidden text for screen readers describing the file type or window behavior.
  • Always include rel="noopener noreferrer" for new-window links.
  • Ensure link text is descriptive (e.g., โ€œDownload 2023 Reportโ€ instead of โ€œClick Hereโ€).
๐Ÿ“ Perfect Implementation Reference
<a href="stats.pdf" target="_blank" rel="noopener">
  Quarterly Stats
  <span class="sr-only">(PDF, opens in new window)</span>
  <svg>...</svg>
</a>

Technical Deep Dive

Screen Reader Announcements

  • VoiceOver: โ€œDownload Annual Report, PDF, 2.4 megabytes, opens in new window, linkโ€
  • NVDA: โ€œDownload Annual Report PDF 2.4 megabytes opens in new window linkโ€

CSS Technique

The .sr-only class is essential for providing descriptions that donโ€™t appear visually but are perfectly readable by assistive technology.

๐Ÿงช

Interactive Behavioral Lab

๐Ÿ’ป

Interactive Sandbox

LIVE PREVIEW

๐Ÿ”ฌ Technical Internals

Understand how this component is processed by the browser and Assistive Technology (AT). This section bridges the gap between visual code and the hidden logic that powers accessibility.

๐ŸŒฒ Accessibility Tree

The data structure used by screen readers to "see" your page. It translates HTML roles and attributes into standardized objects.

โš™๏ธ Event Logic

Expected behavioral standards for keyboard navigation and state transitions. Crucial for users who don't use a mouse.

  • Focus: Highlights via :focus-visible
  • Activation: Responds to Enter and Space
  • Role: Identified as Link

๐ŸŒ Browser & Screen Reader Compatibility

Browser
Screen Reader
Status
๐ŸŽ Safari
VoiceOver
โœ“ Safe
๐ŸชŸ Chrome
NVDA
โœ“ Safe
๐ŸชŸ Edge
JAWS
โœ“ Safe
๐ŸฆŠ Firefox
NVDA
โœ“ Safe
๐Ÿ“ฑ iOS Safari
VoiceOver
โœ“ Safe
๐Ÿค– Chrome Android
TalkBack
โœ“ Safe