HTML oninput Attribute

❮ HTML Attributes


<label for="myInput">Enter your first name:</label> <input type="text" id="myInput" oninput="myFunction()">

<p>You wrote: <output id="demo"></output></p>

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


The oninput attribute fires when the value of an element is changed by the user.

Standard Syntax

<element oninput="script">

Browser Support


Applies to:

The oninput attribute can be used on the following element:

Element Attribute
All HTML elements. oninput

Attribute Values

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