Links with Event Handlers and No Href Attribute: Enhancing Web Accessibility
Understanding the Importance of Links with Hrefs
Links are fundamental components of web navigation, enabling users to jump from one page to another. However, links that utilize event handlers without a proper href attribute can lead to significant accessibility barriers. These barriers affect users relying on assistive technologies, such as screen readers, which expect links to have a defined destination. In this article, we will explore best practices for using links correctly while emphasizing the importance of adhering to the W3C Web Accessibility Guidelines (WCAG) 2.2.
Challenges with Event Handlers
When developers create links using JavaScript event handlers (e.g., onclick) without providing an href attribute, the link may not be recognized as a navigational element. This can result in:
- Poor user experience for keyboard and screen reader users.
- Links that are not focusable, leading to missed navigation opportunities.
- Violation of accessibility guidelines, potentially exposing organizations to legal risks.
Practical Development Advice
To ensure links are accessible, always include an href attribute even when the link triggers JavaScript events. Here’s how to do it correctly:
<a href="#" onclick="yourFunction();" role="button">Click Me</a>
In this example, the link has both an href attribute set to # (which indicates it navigates to the top of the page) and an onclick event for JavaScript functionality. Additionally, the role="button" attribute informs assistive technologies that this link functions as a button.
Semantic Markup Patterns
Using semantic markup is crucial for accessibility. Below is a better approach to creating a clickable element that functions as a link but remains accessible:
<a href="/path/to/destination" aria-label="More information about this topic">Learn More</a>
This implementation provides a direct link to a page while ensuring users with assistive technologies can understand its purpose through the aria-label.
Clear Layout Validation Guidance
To validate that your links conform to accessibility standards, consider the following steps:
- Use validation tools like the W3C Markup Validation Service to check for proper HTML structure.
- Perform accessibility audits using the WP ADA Compliance Check Plugin to identify any links that lack
hrefattributes. - Engage with users who utilize assistive technologies to gather feedback on the usability of your links.
How to Remediate Issues with WP ADA Compliance Check
Manually tracking down hidden structural code fragments across a massive content catalog or a complex multi-author site can take dozens of tedious hours. Deploying a comprehensive tool like the WP ADA Compliance Check Plugin completely automates the process of auditing, reporting, and sometimes correcting critical web accessibility errors.
Automated Remediation
The plugin evaluates your database content against 83 thorough accessibility checks and automatically corrects 42 distinct error types. During deep site scans, it uncovers hidden errors and highlights the exact location of the issue, saving developers from manually hunting through the raw HTML editor.
Enforcing Pre-Publishing Safeguards
To ensure that new content modifications don’t break compliance, the plugin features robust Pre-Publishing Controls. If an editor tries to publish a page containing web accessibility errors, the plugin alerts the user or restricts publication. This content safeguard forces correction at the workflow source before the page goes live.
Getting Started
If you are not sure where to begin with web accessibility, start by using the WP ADA Compliance Check Free Web Accessibility Scanner to run a scan of your website. For a more integrated solution, WordPress website owners should also try the free WP ADA Compliance Check Basic plugin to automatically audit posts and pages for common compliance issues right from their dashboard.
Subscribe
Subscribe to receive daily Web Accessibility - Did you know? articles in your inbox.

