In JavaScript, the focusin event fires when an element has received focus, after the focus event (MDN). The two differ in that focusinbubbles, while focus does not. The opposite is focusout. The event object is a FocusEvent.
Register a listener with addEventListener. Check readiness and browser support before you rely on this event.
Syntax
Listen for focusin. Start with this line.
JavaScript
el.addEventListener("focusin", fn)
Call
What it does
el.addEventListener("focusin", fn)
Primary signature.
Built into the browser. Listen with el.addEventListener("focusin", …) — no import required.
Library declarations
JavaScript
el.addEventListener("focusin", fn)
Parameters
Parameter
Description
FocusEvent
Required. Carries target and relatedTarget
Focusable control
Required. Input, button, link with tabindex, etc.
focusout
Optional. Cleanup when focus leaves
Return Value
Return Value
Description
*
Fires as an Element event (listener receives the Event object).
JavaScript Examples
Example 1 — Form Delegation (MDN)
One focusin / focusout pair on the form styles every child control.
FocusEvent.relatedTarget. For focusin, this is the element losing focus (if any).
Tab between fields.from becomes the previous control.
First focus in the page.relatedTarget may be null.
Use carefully. Always null-check before reading properties.
Compatibility
Browser Support
Element focusin is a standard UI Events focus event. MDN marks it Baseline Widely available since March 2017 — safe for everyday use in modern browsers.
✓ Baseline Widely available
Element focusin
Bubbling FocusEvent after focus — ideal for form-wide focus listeners.
WideBaseline
Google ChromeSupported · Desktop & Mobile
Full support
Mozilla FirefoxSupported · Desktop & Mobile
Full support
Apple SafariSupported · macOS & iOS
Full support
Microsoft EdgeSupported · Chromium
Full support
Internet ExplorerNo native support · Use a polyfill
Polyfill
OperaSupported · Modern versions
Full support
Samsung InternetSupported · Android
Full support
Android WebViewSupported · Modern WebView
Full support
focusinWidely available
Bottom line: Prefer focusin for parent delegation. Use focus when you only care about that element. Pair with focusout for leave cleanup.
Frequently Asked Questions
It fires when an element has received focus, after the focus event (MDN). Unlike focus, focusin bubbles, so you can listen on a parent and still hear when child controls gain focus.
No. MDN marks Element focusin as Baseline Widely available (since March 2017). It is not Deprecated, Experimental, or Non-standard.
Both fire when an element receives focus. focus does not bubble; focusin does, and it fires after focus. For form-wide listeners, focusin is usually simpler.
A FocusEvent (inherits from UIEvent and Event). relatedTarget is the element that is losing focus, if any.
No. MDN states the focusin event is not cancelable.
focusout — it fires when the element loses focus (after blur) and also bubbles.