# On Focus: No Surprises When Elements Get Focus

Source: https://allyway.ai/glossary/on-focus

On Focus is WCAG success criterion 3.2.1. When any user interface component receives focus, it must not initiate a change of context – such as submitting a form, opening a new window or moving focus elsewhere.

On Focus is the WCAG rule that simply moving to an element must never trigger a big change. When someone presses Tab and lands on a link, a field or a button, nothing should open, submit or jump away – only activating the element may do that. It keeps pages predictable for everyone who navigates with the keyboard or a screen reader.

## What it means

[WCAG 3.2.1 On Focus](https://www.w3.org/WAI/WCAG22/Understanding/on-focus.html) is a Level A criterion of [WCAG 2.2](https://allyway.ai/regulations/wcag-2-2). Its text is short: "When any user interface component receives focus, it does not initiate a change of context."

A **change of context** is a major change that can disorient people who cannot see the whole page at once. W3C names four kinds: a change of user agent, of viewport, of focus, or of content that changes the meaning of the page. Showing a little extra content is not a change of context on its own.

| What happens when an element gets focus | Allowed under 3.2.1? |
|---|---|
| A tooltip or hint appears next to the field | Yes – content change only |
| The element gets a visible focus outline | Yes |
| The form is submitted | No |
| A new window or pop-up opens | No |
| Focus is moved to another element | No |
| The browser navigates to another page | No |

People affected most are [keyboard navigation](https://allyway.ai/glossary/keyboard-navigation) users, who have to pass every element on the way to their target, and [screen reader](https://allyway.ai/glossary/screen-reader) users, who may not notice that the page changed under them. People with cognitive disabilities also lose orientation when a page reacts in unexpected ways.

Focus can arrive by keyboard or by mouse click. Hovering with the mouse does not move focus unless a script makes it do so – content that appears on hover is covered by [content on hover or focus](https://allyway.ai/glossary/content-on-hover-or-focus) instead.

> **Note:** > **Activate, don't focus**
> W3C's sufficient technique G107 is simple: use "activate" (click, Enter, Space) instead of "focus" as the trigger for any change of context.

## Examples

```html title="Example"
<!-- Bad: tabbing onto the field opens a new window -->
<input type="text" id="coupon" onfocus="window.open('/coupon-help')">

<!-- Bad: focus is pushed away as soon as it arrives (failure F55) -->
<a href="/terms" onfocus="this.blur()">Terms</a>

<!-- Good: the help opens only when the user asks for it -->
<label for="coupon2">Coupon code</label>
<input type="text" id="coupon2" aria-describedby="coupon-hint">
<p id="coupon-hint">You find the code in your welcome email.</p>
<button type="button" id="coupon-help">Coupon help</button>
```

W3C also lists a failing pattern from real sites: a help dialog that opens whenever a field receives focus and pulls focus away each time the user tabs past it. The user never gets beyond that field.

**Do:** Do

Trigger navigation, submission and pop-ups only on click, Enter or Space. Let menus show their options while the user moves through them, and navigate only when a choice is activated. Keep a visible focus outline on every element.

**Don't:** Don't

Submit a form, open a window or start a redirect in an `onfocus` handler. Never call `blur()` or move focus to another element just because focus arrived. Don't auto-open dialogs when a field is reached.

## How to check On Focus



## Questions

Q: What is a change of context in WCAG?
A: A change of context is a major change of the user agent, the viewport, the focus or the meaning of the page – for example opening a new window, loading another page or moving focus. Small content changes, such as showing a hint, are not a change of context.

Q: Can a dropdown menu open on focus?
A: Yes. Showing the options of a menu is a change of content, not of context. W3C's passing example is a menu where users move through the options with the keyboard and only activating a choice loads a new page.

Q: What is the difference between On Focus and On Input?
A: On Focus (3.2.1) covers the moment an element receives focus. [On Input](https://allyway.ai/glossary/on-input) (3.2.2) covers the moment the user changes a setting, such as choosing an option in a select list or ticking a checkbox.

Q: Is it allowed to move focus automatically?
A: Not as a reaction to focus arriving. Moving focus after the user activates something – for example into a dialog they opened – is expected and fine. Moving focus away the moment an element is reached fails On Focus and, according to W3C, also keyboard and focus visibility rules.
