• Web APIs
  • caches
  • credentialless Experimental
  • devicePixelRatio
  • documentPictureInPicture Experimental
  • event Deprecated
  • external Deprecated
  • fence Experimental
  • fullScreen Non-standard
  • innerWidth
  • launchQueue Experimental
  • locationbar
  • mozInnerScreenX Non-standard
  • mozInnerScreenY Non-standard
  • navigation Experimental
  • orientation Deprecated
  • originAgentCluster Experimental
  • performance
  • screenLeft
  • scrollbars
  • scrollMaxX Non-standard
  • scrollMaxY Non-standard
  • sessionStorage
  • sharedStorage Experimental
  • status Deprecated
  • trustedTypes
  • atob()
  • back() Non-standard Deprecated
  • blur() Deprecated
  • captureEvents() Deprecated
  • clearImmediate() Non-standard Deprecated
  • confirm()
  • dump() Non-standard
  • find() Non-standard
  • forward() Non-standard Deprecated
  • getDefaultComputedStyle() Non-standard
  • getScreenDetails() Experimental
  • moveTo()
  • prompt()
  • queryLocalFonts() Experimental
  • releaseEvents() Deprecated
  • requestFileSystem() Non-standard Deprecated
  • scroll()
  • scrollByLines() Non-standard
  • scrollByPages() Non-standard
  • setImmediate() Non-standard Deprecated
  • setResizable() Non-standard Deprecated
  • showDirectoryPicker() Experimental
  • showModalDialog() Non-standard Deprecated
  • showOpenFilePicker() Experimental
  • showSaveFilePicker() Experimental
  • sizeToContent() Non-standard
  • webkitConvertPointFromNodeToPage() Non-standard Deprecated
  • webkitConvertPointFromPageToNode() Non-standard Deprecated
  • Events
    1. beforeprint
    2. cut
    3. error
    4. hashchange
    5. messageerror
    6. orientationchange Deprecated
    7. pageswap
    8. resize
    9. scrollsnapchange Experimental
    10. scrollsnapchanging Experimental
    11. unload Deprecated
    12. vrdisplayactivate Non-standard Deprecated
    13. vrdisplayconnect Non-standard Deprecated
    14. vrdisplaydeactivate Non-standard Deprecated
    15. vrdisplaydisconnect Non-standard Deprecated
    16. vrdisplaypresentchange Non-standard Deprecated
  • Inheritance
    1. Learn more
    2. See full compatibility
  • The blur event fires when an element has lost focus.

    The opposite of blur is focus.

    This event is not cancelable and does not bubble.

    Syntax

    Use the event name in methods like addEventListener(), or set an event handler property.

    js
    addEventListener("blur", (event) => {});
    
    onblur = (event) => {};
    

    Event type

    Event properties

    This interface also inherits properties from its parent Event.

    FocusEvent.relatedTarget

    An EventTarget representing a secondary target for this event. In some cases (such as when tabbing in or out a page), this property may be set to null for security reasons.

    Examples

    Live example

    This example changes the appearance of a document when it loses focus. It uses focus and blur events.

    HTML

    html
    <p id="log">Click on this document to give it focus.</p>
    

    CSS

    css
    .paused {
      background: #ddd;
      color: #555;
    }
    

    JavaScript

    js
    function pause() {
      document.body.classList.add("paused");
      log.textContent = "FOCUS LOST!";
    }
    
    function play() {
      document.body.classList.remove("paused");
      log.textContent =
        "This document has focus. Click outside the document to lose focus.";
    }
    
    const log = document.getElementById("log");
    
    window.addEventListener("blur", pause);
    window.addEventListener("focus", play);
    

    Result