Receiving focus must not trigger a change of context
Rule
on-focus-context-change· Forms · impact serious · Static + live
Why it matters
Merely tabbing onto an element must be safe. An onfocus handler that submits or navigates means keyboard users cannot even pass over the element without being yanked somewhere else; onfocus="this.blur()" is as bad — it makes the element impossible to reach by keyboard at all. Only inline handlers are visible to static analysis.
How to fix
Trigger navigation and submission from explicit activation (click/Enter), never from focus. Remove blur-on-focus hacks; use tabindex="-1" if something must not be tabbable.
Example
<input aria-label="Coupon code" onfocus="this.blur()">
<input aria-label="Coupon code" onfocus="this.select()">
Example
<a href="/cart" onfocus="window.location='/checkout'">Cart</a>
<a href="/cart" onfocus="highlight(this)">Cart</a>
WCAG success criteria
3.2.1 On Focus — Level A
Merely receiving focus must never trigger a change of context (navigation, form submission, a new window, or moved focus).
Standards
This rule contributes to the following standards:
WCAG A EN 301 549 Section 508 Trusted Tester
| Standard | Criteria |
|---|---|
| Section 508 | 3.2.1 |
| EN 301 549 | 9.3.2.1 |