
- HTML Home
- HTML Roadmap
- HTML Introduction
- HTML History & Evolution
- HTML Editors
- HTML Basic Tags
- HTML Elements
- HTML Attributes
- HTML Headings
- HTML Paragraphs
- HTML Fonts
- HTML Blocks
- HTML Style Sheet
- HTML Formatting
- HTML Quotations
- HTML - Comments
- HTML - Colors
- HTML - Images
- HTML - Image Map
- HTML - Frames
- HTML - Iframes
- HTML - Phrase Elements
- HTML - Code Elements
- HTML - Meta Tags
- HTML - Classes
- HTML - IDs
- HTML - Backgrounds
- HTML Tables
- HTML - Tables
- HTML - Table Headers & Captions
- HTML - Table Styling
- HTML - Table Colgroup
- HTML - Nested Tables
- HTML Lists
- HTML - Lists
- HTML - Unordered Lists
- HTML - Ordered Lists
- HTML - Definition Lists
- HTML Links
- HTML - Text Links
- HTML - Image Links
- HTML - Email Links
- HTML Color Names & Values
- HTML - Color Names
- HTML - RGB & RGBA Colors
- HTML - HEX Colors
- HTML - HSL & HSLA Colors
- HTML - HSL Color Picker
- HTML Forms
- HTML - Forms
- HTML - Form Attributes
- HTML - Form Control
- HTML - Input Attributes
- HTML Media
- HTML - Video Element
- HTML - Audio Element
- HTML - Embed Multimedia
- HTML Header
- HTML - Head Element
- HTML - Adding Favicon
- HTML - Javascript
- HTML Layouts
- HTML - Layouts
- HTML - Layout Elements
- HTML - Layout using CSS
- HTML - Responsiveness
- HTML - Symbols
- HTML - Emojis
- HTML - Style Guide
- HTML Graphics
- HTML - SVG
- HTML - Canvas
- HTML APIs
- HTML - Geolocation API
- HTML - Drag & Drop API
- HTML - Web Workers API
- HTML - WebSocket
- HTML - Web Storage
- HTML - Server Sent Events
- HTML Miscellaneous
- HTML - Document Object Model (DOM)
- HTML - MathML
- HTML - Microdata
- HTML - IndexedDB
- HTML - Web Messaging
- HTML - Web CORS
- HTML - Web RTC
- HTML Demo
- HTML - Audio Player
- HTML - Video Player
- HTML - Web slide Desk
- HTML Tools
- HTML - Velocity Draw
- HTML - QR Code
- HTML - Modernizer
- HTML - Validation
- HTML - Color Picker
- HTML References
- HTML - Cheat Sheet
- HTML - Tags Reference
- HTML - Attributes Reference
- HTML - Events Reference
- HTML - Fonts Reference
- HTML - ASCII Codes
- ASCII Table Lookup
- HTML - Color Names
- HTML - Character Entities
- MIME Media Types
- HTML - URL Encoding
- Language ISO Codes
- HTML - Character Encodings
- HTML - Deprecated Tags
- HTML Resources
- HTML - Quick Guide
- HTML - Useful Resources
- HTML - Color Code Builder
- HTML - Online Editor
HTML - DOM blur() Method
The HTML DOMblur()method is used to remove keyboard focus dynamically from an element in the HTML DOM. Removing focus from an element refers to shifting the keyboard focus away from a specific element, such as an input field or a button.
The DOM provides another method namedfocus(), which you can use to give focus on any Element in HTML DOM.
Syntax
Following is the syntax of the HTML DOM blur() method −
Object.blur();
Parameters
This method does not accept any parameter.
Return Value
This method does not return any value.
Example 1: Remove Focus from the Input Field
The following is the basic example of the HTML DOM blur() method to remove focus from an input field when a button is clicked −
<!DOCTYPE html> <html lang="en"> <head> <title>HTML DOM blur()</title> </head> <body> <p>Click the button to blur the input field.</p> <input type="text" id="myInput" placeholder="Type something..."> <button onclick="blurInput()">Blur Input</button> <script> function blurInput() { const input = document.getElementById('myInput'); input.blur(); } </script> </body> </html>
Example 2: blur() method on anchor (<a>) element
Following is another example of the HTML DOM blur() method. We use this method to remove focus from an anchor (<a>) element −
<!DOCTYPE html> <html lang="en"> <head> <title>HTML DOM blur()</title> </head> <body> <p>Click the button to blur the anchor element.</p> <a id="myAnchor" href="https://www.example.com">Example Anchor</a> <button onclick="blurAnchor()">Blur Anchor Element</button> <script> function blurAnchor() { const myAnchor = document.getElementById('myAnchor'); myAnchor.blur(); alert('Anchor element blurred!'); } </script> </body> </html>
Example 3: Blurred on Clicking Anywhere
The below example shows how the blur() method works with the event listener. When you click the input field and outside the field, a pop-up will display with the message "Input field is blurred" −
<!DOCTYPE html> <html lang="en"> <head> <title>HTML DOM blur()</title> </head> <body> <p>Click anywhere outside the input field to blur it.</p> <input type="text" id="myInput" value="Edit Me!"> <script> const myInput =document.getElementById('myInput'); myInput.addEventListener('blur', () => { alert('Input field blurred!'); }); </script> </body> </html>
Supported Browsers
Method | ![]() |
![]() |
![]() |
![]() |
![]() |
---|---|---|---|---|---|
blur() | Yes | Yes | Yes | Yes | Yes |