HTML onblur Attribute

❮ HTML Attributes


<input type="text" name="fname" id="fname" onblur="myFunction()">

<p id="demo"></p>

function myFunction() {
  var x = document.getElementById("fname");
  document.getElementById("demo").innerHTML = x.value;


The onblur attribute occurs when an element loses focus, meaning that the user has moved focus to another element, typically either by clicking the mouse or by tabbing.

Standard Syntax

<element onblur="script">

Browser Support


Applies to:

The onblur attribute can be used on the following element:

Element Attribute
All HTML elements onblur

Attribute Values

Value Description
script Specifies the script to be run on onblur.
❮ HTML Attributes