All posts

HTML a onclick: Correct Syntax, SEO & Accessibility Rules

August 21, 2026

Most advice on html a onclick lands in one of two unhelpful extremes: "never put onclick on a link" or "just slap onclick on anything clickable." Neither is accurate. The real rule: onclick on an tag is fine — even keyboard-accessible — as long as the tag still has a genuine href. The moment href disappears, gets left empty, or gets replaced with a javascript: pseudo-URL, that same onclick becomes an SEO dead end and an accessibility trap.

What Does onclick Do on an Tag?

The onclick attribute is a JavaScript event handler, not a navigation mechanism. It tells the browser "run this script when the user clicks this element" — nothing more. It works the same way on a

, a

Originally published on Rankevra.