Seoxpert.io
lowOn-Page SEO

Anchors with `onclick` But No `href`

Anchors with `onclick` but no `href` are not accessible or usable as links for all users and devices.

By Seoxpert Editorial · Published

Why it matters

Links without `href` are not accessible to keyboard users and are not recognized as links by screen readers. This breaks standard browser behaviors like opening in a new tab or copying the link, harming both accessibility and user experience.

Impact

Leaving this unresolved excludes keyboard and assistive tech users, and may reduce site usability and accessibility compliance.

How it's detected

Automated crawlers scan for `<a>` elements with an `onclick` attribute but missing or empty `href` attributes.

Common causes

  • Using `<a>` for actions instead of navigation
  • Forgetting to add `href` when using JavaScript navigation
  • Using anchors as generic clickable elements for styling
  • Copy-pasting code without updating the `href`
  • SPA routing without proper `href` fallback

How to fix it

If the element performs an action (not navigation), use a `<button type="button">` instead of an anchor. If it navigates, provide a valid `href` and use JavaScript to handle SPA routing if needed. Avoid using `<a>` as a generic clickable element; reserve it for real navigation.

Code examples

Problem: Anchor with onclick but no href

<a onclick="doSomething()">Click me</a>

Fix 1: Use button for actions

<button type="button" onclick="doSomething()">Click me</button>

Fix 2: Use anchor with href for navigation

<a href="/destination" onclick="navigateSPA(event)">Go to page</a>
<script>
function navigateSPA(e) {
  e.preventDefault();
  // SPA navigation logic here
}
</script>

FAQ

Why is an anchor without href a problem for accessibility?

Without an href, anchors are not focusable by keyboard and are not announced as links by screen readers, making them inaccessible.

Can I use JavaScript to handle navigation with anchors?

Yes, but you must still provide a valid href for accessibility and standard browser behavior, even if JavaScript intercepts the click.

When should I use a button instead of an anchor?

Use a button for actions that do not involve navigation, such as submitting forms or triggering UI changes.

Does this affect SEO rankings?

While not a direct ranking factor, poor accessibility and broken navigation can negatively impact user experience and site reputation.

Found this issue on your site?

Run a scan to see if Anchors with `onclick` But No `href` affects your pages.

Scan my website →