JavaScript Element focusout Event

Beginner
⏱️ 11 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
DOM event
Instance event

What You’ll Learn

The focusout event fires after blur when an element loses focus—and unlike blur, it bubbles. Learn onfocusout, form cleanup, relatedTarget, the focusin pair, and five try-it labs.

01

Kind

Instance event

02

Type

FocusEvent

03

Bubbles?

Yes

04

Handler

onfocusout

05

Pair

focusin

06

Status

Limited availability

Introduction

blur is perfect when you attach a listener directly to one control. When you want one listener on a form or dialog to react to every child that loses focus, focusout is the event designed for that job because it bubbles.

It fires after blur. Its opposite is focusin (which bubbles after focus). MDN marks focusout as Limited availability (not Baseline)—still widely useful, but always verify support for your audience.

💡
Beginner tip

Use focusout to clear highlights, hide hints, or run “validate when the user leaves the field” logic for many inputs with a single parent listener.

Understanding focusout

An instance event that answers: “Did this element (or a descendant) just lose focus?” when you listen on an ancestor.

  • Fires after blur when an element loses focus.
  • Bubbles — ideal for event delegation on forms and containers.
  • Not cancelable — you cannot keep focus by calling preventDefault().
  • FocusEventrelatedTarget is the element receiving focus (if any).
  • Handleronfocusout or addEventListener("focusout", ...).
  • Limited availability on MDN (not Baseline)—test carefully.

📝 Syntax

Use the event name with addEventListener, or set the handler property:

JavaScript
addEventListener("focusout", (event) => { });

onfocusout = (event) => { };

Event type

A FocusEvent (inherits from UIEvent and Event).

Handy properties

PropertyMeaning
targetThe element losing focus (often a child of your listener)
currentTargetThe element you attached the listener to (e.g. the form)
relatedTargetThe element receiving focus, if any (may be null)
bubblestrue for focusout
cancelablefalse — not cancelable

🔁 Event Order (A → B)

When focus moves from element A to element B, browsers typically dispatch:

  1. blur on A
  2. focusout on A (bubbles)
  3. focus on B
  4. focusin on B (bubbles)

So cleanup for A usually happens before setup for B. MDN notes that the UI Events specification describes an order that can differ from what current browsers implement—avoid fragile assumptions beyond this common pattern.

⚖️ focusout vs blur

Topicblurfocusout
WhenElement loses focusSame moment, after blur
Bubbles?NoYes
Best forListener on the element itselfDelegation on a parent
Opposite pairfocusfocusin
relatedTargetElement receiving focus (if any)Element receiving focus (if any)
MDN statusBaseline Widely availableLimited availability (not Baseline)
🔔
Fallback idea

If you must support environments where focusout is awkward, you can still delegate with addEventListener("blur", handler, true) (capture phase). Prefer focusout when it is available and clearer.

⚡ Quick Reference

GoalCode / note
Listen on one controlel.addEventListener("focusout", fn)
Handler propertyel.onfocusout = fn
Delegate on a formform.addEventListener("focusout", fn)
Highlight + clearPair with focusin
Where focus wentevent.relatedTarget (may be null)
MDN statusLimited availability (not Baseline)

🔍 At a Glance

Four facts to remember about focusout.

Event type
FocusEvent

After blur

Means
lost focus

Bubbling signal

Bubbles
yes

Great for forms

Baseline
no

Limited availability

Examples Gallery

Examples follow MDN Element: focusout event. Tab or click between fields to trigger focusout.

📚 Getting Started

MDN form styling cleanup and the onfocusout property.

Example 1 — Form Cleanup (MDN)

Clear the pink highlight when any child control loses focus.

JavaScript
const form = document.getElementById("form");

form.addEventListener("focusin", (event) => {
  event.target.style.background = "pink";
});

form.addEventListener("focusout", (event) => {
  event.target.style.background = "";
});
Try It Yourself

How It Works

focusout is the cleanup half of the MDN pair. Without it, styles from focusin would stick after the user leaves the field.

Example 2 — onfocusout Property

Log which field lost focus using the handler property form.

JavaScript
const form = document.getElementById("form");
const out = document.getElementById("out");

form.onfocusout = (event) => {
  out.textContent =
    "focusout from " + (event.target.name || event.target.tagName);
};
Try It Yourself

How It Works

Prefer addEventListener when you need multiple listeners. The property form is fine for short demos.

📈 Compare, relatedTarget & Validation

Prove bubbling, see where focus went, validate on leave.

Example 3 — Prove blur Does Not Bubble

Parent listeners: focusout sees children; bubble-phase blur does not.

JavaScript
const form = document.getElementById("form");
const out = document.getElementById("out");

form.addEventListener("blur", () => {
  out.textContent += "parent blur (bubble)\n";
});

form.addEventListener("focusout", (event) => {
  out.textContent +=
    "parent focusout ← " + (event.target.name || event.target.tagName) + "\n";
});
Try It Yourself

How It Works

Capture-phase blur would still see children; bubble-phase blur on the form will not.

Example 5 — Validate When Leaving a Field

Practical UX: check required inputs on focusout via one form listener.

JavaScript
const form = document.getElementById("form");
const msg = document.getElementById("msg");

form.addEventListener("focusout", (event) => {
  const el = event.target;
  if (!(el instanceof HTMLInputElement)) return;
  if (el.required && !el.value.trim()) {
    msg.textContent = el.name + " is required";
    el.style.outline = "2px solid tomato";
  } else {
    msg.textContent = "";
    el.style.outline = "";
  }
});
Try It Yourself

How It Works

Soft validation on leave complements submit-time checks. Keep error text clear and do not rely only on color for accessibility.

🚀 Common Use Cases

  • Clear focus highlights when any field inside a form blurs.
  • Hide contextual help that was shown on focusin.
  • Run soft validation when the user leaves a control.
  • Track focus exits for analytics or accessibility demos.
  • Teach event bubbling vs the non-bubbling blur event.

🔧 How It Works

1

User leaves a control

Tab away, click elsewhere, or focus moves programmatically.

Input
2

blur fires on the target

Does not bubble to ancestors in the bubble phase.

Target
3

focusout fires and bubbles

Parent form / dialog listeners can clean up or validate.

Bubble
4

New element may focusin

relatedTarget often points at the next focused control.

📝 Notes

Limited Availability Support

focusout is marked Limited availability on MDN (not Baseline). Logos use the shared browser-image-sprite.png sprite from this project. It is widely used for form cleanup—still verify support for your audience, and keep capture-phase blur as a mental fallback.

Limited availability

Element focusout

Bubbling blur signal for parent listeners; confirm support in your target browsers.

Limited Not Baseline
Google Chrome Supported (check BCD for edge cases)
Supported
Mozilla Firefox Supported in modern versions
Supported
Apple Safari Supported in modern versions
Supported
Microsoft Edge Supported · Chromium
Supported
Opera Supported · Modern versions
Supported
Internet Explorer Legacy support existed; prefer modern browsers
Legacy
focusout Limited

Bottom line: Prefer focusout for form cleanup when available; pair with focusin and test carefully.

Conclusion

focusout is the bubbling “lost focus” signal that follows blur. Use it for form-wide cleanup and soft validation, pair it with focusin, and remember MDN lists it as Limited availability.

Continue with fullscreenchange, addEventListener(), or the JavaScript hub.

💡 Best Practices

✅ Do

  • Prefer addEventListener("focusout", ...) on parents for cleanup
  • Pair with focusin for highlight / hint UX
  • Filter event.target when you only care about inputs
  • Null-check event.relatedTarget
  • Test browsers you support (Limited availability)

❌ Don’t

  • Expect bubble-phase blur on a form to see child fields
  • Rely on preventDefault() to keep focus
  • Leave focus styles stuck after the user leaves a field
  • Assume Baseline Widely available status
  • Overwrite onfocusout if you need multiple listeners

Key Takeaways

Knowledge Unlocked

Five things to remember about focusout

After blur—bubbles; ideal for form cleanup with focusin.

5
Core concepts
📄 02

FocusEvent

relatedTarget = next

API
📤 03

Bubbles

unlike blur

Key
04

Pair focusin

highlight + clear

Pattern
🎯 05

Limited avail.

not Baseline

Status

❓ Frequently Asked Questions

It fires when an element has lost focus, after the blur event. Unlike blur, focusout bubbles, so you can listen on a parent and still hear when child controls lose focus.
No. MDN does not mark it Deprecated, Experimental, or Non-standard. It has Limited availability (not Baseline), so always test the browsers you care about.
Both fire when an element loses focus. blur does not bubble; focusout does, and it fires after blur. For form-wide cleanup, focusout is usually the simpler choice.
A FocusEvent (inherits from UIEvent and Event). relatedTarget is the element receiving focus, if any.
No. The focusout event is not cancelable.
focusin — it fires when the element receives focus (after focus) and also bubbles.
Did you know?

For focusout, relatedTarget points to where focus is going. For focusin, it points to where focus came from. Same property name—opposite direction.

Next: fullscreenchange

Learn when an element enters or leaves fullscreen mode.

fullscreenchange →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

5 people found this page helpful