HTML DOM onblur Event Last Updated : 12 Jul, 2025 Comments Improve Suggest changes Like Article Like Report The HTML DOM onblur event occurs when an object loses focus. The onblur event is the opposite of the onfocus event. The onblur event is mostly used with form validation code (e.g. when the user leaves a form field). In HTML:<element onblur="myScript"> html <!DOCTYPE html> <html lang="en"> <body> Email: <input type="email" id="email" onblur="myFunction()"> <script> function myFunction() { alert("Focus lost"); } </script> </body> </html> In JavaScript:object.onblur = function(){myScript}; html <!DOCTYPE html> <html lang="en"> <body> <input type="email" id="email"> <script> document.getElementById("email").onblur = function () { myFunction() }; function myFunction() { alert("Input field lost focus."); } </script> </body> </html> In JavaScript, using the addEventListener() method:object.addEventListener("blur", myScript); html <!DOCTYPE html> <html lang="en"> <body> <input type="email" id="email"> <script> document.getElementById( "email").addEventListener("blur", myFunction); function myFunction() { alert("Input field lost focus."); } </script> </body> </html> Comment More infoAdvertise with us Next Article Company-wise Practice Problems V Vijay Sirra Follow Improve Article Tags : Web Technologies HTML HTML-DOM Similar Reads Interview PreparationInterview Preparation For Software DevelopersMust Coding Questions - Company-wise Must Do Coding Questions - Topic-wiseCompany-wise Practice ProblemsCompany PreparationCompetitive ProgrammingSoftware Design-PatternsCompany-wise Interview ExperienceExperienced - Interview ExperiencesInternship - Interview ExperiencesPractice @GeeksforgeeksProblem of the DayTopic-wise PracticeDifficulty Level - SchoolDifficulty Level - BasicDifficulty Level - EasyDifficulty Level - MediumDifficulty Level - HardLeaderboard !!Explore More...Data StructuresArraysLinked ListStackQueueBinary TreeBinary Search TreeHeapHashingGraphAdvance Data StructuresMatrixStringAll Data StructuresAlgorithmsAnalysis of AlgorithmsSearching AlgorithmsSorting AlgorithmsPattern SearchingGeometric AlgorithmsMathematical AlgorithmsRandomized AlgorithmsGreedy AlgorithmsDynamic ProgrammingDivide & ConquerBacktrackingBranch & BoundAll AlgorithmsProgramming LanguagesCC++JavaPythonC#Go LangSQLPHPScalaPerlKotlinWeb TechnologiesHTMLCSSJavaScriptBootstrapTailwind CSSAngularJSReactJSjQueryNodeJSPHPWeb DesignWeb BrowserFile FormatsComputer Science SubjectsOperating SystemsDBMSComputer NetworkComputer Organization & ArchitectureTOCCompiler DesignDigital Elec. & Logic DesignSoftware EngineeringEngineering MathematicsData Science & MLComplete Data Science CourseData Science TutorialMachine Learning TutorialDeep Learning TutorialNLP TutorialMachine Learning ProjectsData Analysis TutorialTutorial LibraryPython TutorialDjango TutorialPandas TutorialKivy TutorialTkinter TutorialOpenCV TutorialSelenium TutorialGATE CSGATE CS NotesGate CornerPrevious Year GATE PapersLast Minute Notes (LMNs)Important Topic For GATE CSGATE CoursePrevious Year Paper: CS exams Like