0Pricing
Web Accessibility Academy · Lesson

Moving Focus After an Action

Send focus where the user needs it next.

Moving Focus After an Action is a free Web Accessibility Academy lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Web Accessibility Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Focus Is the User's Cursor

For keyboard and screen reader users, focus is where they are on the page. After an action, you decide where that point lands next.

Why Move Focus at All

When a button reveals new content, focus often stays put and the user never learns anything changed. Moving focus brings them to the result.

The focus Method

You move focus in JavaScript by calling element.focus() on the target you want the user to land on next.

document.getElementById('results').focus();

Make the Target Focusable First

A plain div will not accept focus, so give the destination tabindex="-1" so your script can move focus to it.

<div id="results" tabindex="-1">3 matches found</div>

Example: Reveal and Focus

After loading new content, show it and then send focus there so the screen reader starts reading the new region. 🔎

panel.hidden = false;
panel.focus();

Focus the Heading, Not the Whole Region

Pointing focus at the new section's heading often reads best, giving the user a clear title for where they just arrived.

Deleting an Item

When the user removes a row, focus would otherwise be lost. Move it to the next item or a nearby control so they can keep going.

Avoid the Focus-to-Top Jolt

Letting focus snap back to the page top after every action is jarring. Aim it at the relevant spot instead so context is preserved.

Do Not Steal Focus Randomly

Only move focus in response to a user action. Grabbing it during background updates yanks people out of whatever they were doing.

Confirm It Worked

Test by triggering the action with the keyboard and watching the focus ring land where you intended, every single time.

One Move Per Action

Each meaningful action should result in exactly one deliberate focus move. Predictable beats clever every time.

Quick Check

You want to move focus to a freshly shown div after a button click. What must the div have?

Recap

You learned to move focus on purpose: make the target focusable with tabindex="-1", call focus() after the action, and aim for the most useful spot. ✨

Frequently asked questions

Is the “Moving Focus After an Action” lesson free?

Yes — the full text of “Moving Focus After an Action” is free to read here on the web, and the Web Accessibility Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Web Accessibility Academy course, upgrade to CoddyKit PRO.

What will I learn in “Moving Focus After an Action”?

Send focus where the user needs it next. You practise Web Accessibility Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Web Accessibility Academy?

No prior experience is required. Web Accessibility Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Moving Focus After an Action” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Web Accessibility Academy lesson?

Yes. Every Web Accessibility Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. tabindex 0, -1, and Never Positive
  2. Moving Focus After an Action
  3. Returning Focus When a Layer Closes
  4. Managing roving tabindex in Widgets
← Back to Web Accessibility Academy