The window.blur() method removes focus from the browser window. This tutorial covers syntax, how it differs from element.blur(), listening for the window blur event, five examples, and when the method is actually useful.
01
Syntax
window.blur()
02
Target
Browser window/tab
03
Pair
Opposite of focus()
04
Event
blur on window
05
Not input
Not input.blur()
06
Return
undefined
Fundamentals
Introduction
Every browser tab has a focused state: when your tab is active, the window has focus. When you switch to another tab or application, the window loses focus and a blur event fires. The window.blur() method lets JavaScript request that same “unfocused” state programmatically.
Beginners often confuse window.blur() with blurring a form field. Form controls use HTMLElement.blur() instead. This page covers the window method only—the API on the global browser window object.
Concept
Understanding the blur() Method
window.blur() takes no arguments and returns undefined. It asks the browser to move focus away from the current window. In practice, the visual effect is often minimal because browsers limit scripts from aggressively controlling focus for security and usability reasons.
The more common pattern in modern apps is listening for the blur event to detect when the user leaves your tab—useful for pausing video, autosaving drafts, or stopping timers.
💡
Beginner Tip
To remove focus from a text box, call document.getElementById('email').blur() on that element. To handle the whole tab losing focus, use window.addEventListener('blur', ...).
Foundation
📝 Syntax
General form of Window.blur():
JavaScript
window.blur();
// shorthand (same in browsers):
blur();
Parameters
None.
Return value
undefined.
Related APIs
window.focus() — try to focus the window (often restricted without user gesture).
window.addEventListener("blur", fn) — run code when the tab loses focus.
element.blur() — remove focus from a specific HTML element.
Cheat Sheet
⚡ Quick Reference
Topic
Detail
Call form
window.blur()
Opposite
window.focus()
Form field blur
element.blur() (different API)
Detect tab switch
windowblur event
Arguments
None
Return value
undefined
Compare
📋 window.blur() vs element.blur()
Same method name, different objects. Pick the API that matches what you want to unfocus.
Window
window.blur()
Unfocus the tab/window
Element
input.blur()
Unfocus one field
Event
window "blur"
User left the tab
Focus pair
window.focus()
Try to refocus window
Hands-On
Examples Gallery
Open DevTools Console (F12) or use the Try-it links. Some effects depend on browser focus rules—the event listener examples are the most reliable way to observe blur behavior.
📚 Getting Started
Call window.blur() and observe what happens.
Example 1 — Call window.blur() on Button Click
Invoke the method after a user clicks—browsers are more permissive when focus changes follow user gestures.
JavaScript
document.getElementById("blurBtn").addEventListener("click", function () {
window.blur();
console.log("window.blur() called");
});
The click handler runs in direct response to user input, then calls window.blur(). The console message confirms the method ran—even if the visual unfocus effect is subtle in your browser.
📈 Practical Patterns
Events, pairs, timing, and the element contrast.
Example 2 — Listen for the Window blur Event
Detect when the user switches away from your tab—no need to call blur() yourself.
JavaScript
window.addEventListener("blur", function () {
console.log("Tab lost focus — pause video or autosave here");
});
window.addEventListener("focus", function () {
console.log("Tab is active again");
});
Tab lost focus — pause video or autosave here
(when you return)
Tab is active again
How It Works
The browser fires blur on window when the tab becomes inactive and focus when it becomes active again. This pattern is far more common in production than calling window.blur() directly.
Example 3 — Pair focus() and blur()
Two buttons demonstrate the opposite window methods side by side.
JavaScript
document.getElementById("focusBtn").onclick = function () {
window.focus();
console.log("window.focus() called");
};
document.getElementById("blurBtn").onclick = function () {
window.blur();
console.log("window.blur() called");
};
focus() and blur() are complementary window methods. Remember that refocusing a background tab from script is often blocked unless the user initiated the action.
Example 4 — Delayed blur() with setTimeout
Schedule unfocus after a short delay—useful in pop-up window tutorials.
JavaScript
console.log("Window will call blur() in 2 seconds…");
setTimeout(function () {
window.blur();
console.log("window.blur() called after delay");
}, 2000);
element.blur() removes the caret from the text field but leaves the tab active. Use this for form UX; use window.blur() only when you intentionally target the whole window.
Applications
🚀 Common Use Cases
Tab visibility — listen for blur to pause media or stop animations when the user leaves.
Autosave drafts — save form state when the window loses focus.
Pop-up windows — child windows may call blur() or focus() on the opener in legacy flows.
Analytics — track when users switch tabs during long forms or checkout.
Idle detection — combine blur/focus timestamps with inactivity timers.
Learning demos — compare window methods with element focus APIs.
🧠 What Happens When You Call window.blur()
1
Script invokes blur
Your code calls window.blur() with no arguments.
Call
2
Browser decides
The user agent applies focus policy—effect may be limited or none.
Policy
3
Event may fire
If focus actually leaves, the blur event runs on window.
Event
4
👁
Returns undefined
There is no return value to check—verify behavior with event listeners or logging.
Important
📝 Notes
window.blur() is not the same as the CSS filter: blur() visual effect.
The HTML onblur attribute on inputs listens for element blur, not window blur.
document.hasFocus() returns whether the document currently has focus.
Page Visibility API (document.visibilityState) complements blur events for tab detection.
Avoid surprising users by blurring the window without context—it can feel like the page broke.
In iframes, focus/blur behavior involves the embedded document’s window object.
Compatibility
Browser Support
Window.blur() and the window blur event have been supported across browsers for many years. Behavior when calling blur() programmatically may differ slightly by platform.
✓ Universal · Legacy API
Window.blur()
Supported in Chrome, Firefox, Safari, Edge, and Opera. Event listeners for window blur/focus work consistently for tab switching.
100%Universal support
Google ChromeAll versions · Desktop & Mobile
Full support
Mozilla FirefoxAll versions · Desktop & Mobile
Full support
Apple SafariAll versions · macOS & iOS
Full support
Microsoft EdgeAll versions · Chromium & Legacy
Full support
Internet ExplorerIE 6+ · Legacy environments
Full support
OperaAll modern versions
Full support
blur()Universal
Bottom line: The API exists everywhere, but rely on blur/focus events rather than forcing window.blur() for core product logic—the programmatic call may do little on modern desktops.
Wrap Up
Conclusion
window.blur() removes focus from the browser window and pairs with window.focus(). In everyday development you will more often listen for the blur event or call element.blur() on form fields.
Understanding all three—window method, window event, and element method—keeps your focus management code precise and beginner-friendly.
Use window.addEventListener("blur", …) to detect tab switches
Use element.blur() to leave form fields cleanly
Pair visibility API checks with blur handlers for robust pause logic
Log or test focus changes during development
Respect browser focus restrictions in pop-up flows
❌ Don’t
Confuse window.blur() with input field blur
Depend on window.blur() for critical UX without fallbacks
Call window.focus() repeatedly to grab attention
Assume blur always produces a visible unfocus effect
Use window blur for CSS-style visual blurring
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about window.blur()
Your foundation for window focus management in JavaScript.
5
Core concepts
📝01
Syntax
window.blur()
API
🔌02
Window only
Not input blur.
Scope
🔔03
Event
Tab switch detect.
Listen
🔄04
vs focus()
Opposite pair.
Pair
⚠05
Subtle FX
May do little.
Browser
❓ Frequently Asked Questions
It tells the browser to remove focus from the current window (tab). It is the opposite of window.focus(). The visible effect varies by browser and is often subtle.
No. window.blur() affects the browser window/tab. element.blur() removes focus from a specific HTML element such as an input field. They share a name but target different objects.
The window blur event fires when the user leaves the tab or window—switching tabs, clicking another app, or minimizing. You listen with window.addEventListener('blur', handler).
No. Call it as window.blur() with no parameters. It returns undefined.
Modern browsers restrict focus changes for security. window.blur() may have little or no visible effect, and window.focus() on inactive tabs is often blocked unless triggered by a user gesture.
Rarely. Most apps use element.focus() and element.blur() for form fields. window.blur() appears in pop-up window workflows or legacy patterns—not everyday UI code.
Did you know?
The Page Visibility API (document.visibilityState === "hidden") is often paired with window blur events today. It tells you when a tab is hidden even if focus semantics differ on mobile browsers.