Seoxpert.io
lowOn-Page SEO

Anchors Using `javascript:void(0)` or `javascript:;`

Anchors using `javascript:void(0)` or `javascript:;` suppress navigation but cause accessibility and SEO issues.

By Seoxpert Editorial · Published

Why it matters

Using `javascript:void(0)` in anchor tags is an outdated workaround that creates accessibility, usability, and security problems. It can break keyboard navigation, confuse screen readers, and violate Content-Security-Policy rules, negatively affecting both user experience and SEO.

Impact

Leaving this unresolved can harm accessibility, break functionality for some users, and reduce SEO effectiveness.

How it's detected

Automated crawlers scan for anchor (`<a>`) tags with `href` attributes set to `javascript:void(0)` or `javascript:;`.

Common causes

  • Using anchors for button-like actions instead of real buttons
  • Copy-pasting legacy code patterns
  • Lack of awareness of modern button styling
  • Attempting to prevent default anchor navigation without considering accessibility

How to fix it

Replace `<a href="javascript:void(0)" onclick="...">` with `<button type="button" onclick="...">`. Style the button to look like a link using CSS if needed. This approach is semantically correct, accessible, and compatible with Content-Security-Policy.

Code examples

Problem: Anchor using javascript:void(0)

<a href="javascript:void(0)" onclick="doSomething()">Click me</a>

Solution: Button styled as link

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

<style>
.link-button {
  background: none;
  border: none;
  color: #06c;
  text-decoration: underline;
  cursor: pointer;
}
</style>

FAQ

Why shouldn't I use `javascript:void(0)` in anchor tags?

It causes accessibility, usability, and security issues, and is not the semantically correct way to trigger actions.

Is it safe to replace all `javascript:void(0)` anchors with buttons?

Yes, if the element is meant to trigger an action and not navigate, use a `<button>` instead and style it as needed.

Will replacing anchors with buttons affect my site's SEO?

It improves accessibility and semantics, which can positively impact SEO by making your site more usable and crawlable.

What if I need the element to look like a link?

Use CSS to style the button to look like a link while keeping the correct semantics.

Found this issue on your site?

Run a scan to see if Anchors Using `javascript:void(0)` or `javascript:;` affects your pages.

Scan my website →