W3cubDocs

/Web APIs

Element: focusin event

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

The focusin event fires when an element has received focus, after the focus event. The two events differ in that focusin bubbles, while focus does not.

The opposite of focusin is the focusout event, which fires when the element has lost focus.

The focusin event is not cancelable.

Syntax

Use the event name in methods like addEventListener().

addEventListener("focusin", (event) => { })

Note: There is no onfocusin event handler property for this event.

Event type

A FocusEvent. Inherits from UIEvent and Event.

Event UIEvent FocusEvent

Event properties

This interface also inherits properties from its parent UIEvent, and indirectly from Event.

FocusEvent.relatedTarget

The element losing focus, if any.

Examples

>

Live example

HTML

<form id="form">
  <label>
    Some text:
    <input type="text" placeholder="text input" />
  </label>
  <label>
    Password:
    <input type="password" placeholder="password" />
  </label>
</form>

JavaScript

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

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

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

Result

Specifications

Note: The UI Events specification describes an order of focus events that's different from what current browsers implement.

Browser compatibility

Desktop Mobile
Chrome Edge Firefox Opera Safari Chrome Android Firefox for Android Opera Android Safari on IOS Samsung Internet WebView Android WebView on iOS
focusin_event
1The onfocusin event handler property is not supported. To listen to this event, use element.addEventListener('focusin', function() {});.
12The onfocusin event handler property is not supported. To listen to this event, use element.addEventListener('focusin', function() {});.
52The onfocusin event handler property is not supported. To listen to this event, use element.addEventListener('focusin', function() {});.
11.6 5
18The onfocusin event handler property is not supported. To listen to this event, use element.addEventListener('focusin', function() {});.
52The onfocusin event handler property is not supported. To listen to this event, use element.addEventListener('focusin', function() {});.
12.1 4.2
1.0The onfocusin event handler property is not supported. To listen to this event, use element.addEventListener('focusin', function() {});.
4.4The onfocusin event handler property is not supported. To listen to this event, use element.addEventListener('focusin', function() {});.
4.2

See also

© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/Element/focusin_event