Open In App

HTML onkeyup Event Attribute

Last Updated : 08 Mar, 2024
Like Article

The HTML onkeyup event attribute executes JavaScript code when a user releases a key after pressing it within an input field or textarea, enabling dynamic responses to keyboard input.

It also enables real-time interaction with user input in web forms or applications and is commonly used for live search functionality, password strength checks, or dynamic form validation.


<element onkeyup = "script">

Attribute Value: This attribute contains single value script which works when the keyboard key is released. 

HTML onkeyup Supported Tags

It supports all HTML elements Except- 

HTML onkeyup Event Attribute Examples

Example 1: This example demonstrates the basic implementation of onkeyup tag.


<!DOCTYPE html>
    <title>onkeyup Event Attribute </title>
        h2 {
            text-align: center;
        input[type=text] {
            width: 50%;
            padding: 12px 20px;
            margin: 8px 0;
            box-sizing: border-box;
            font-size: 24px;
            color: white;
        p {
            font-size: 20px;
        Release the key to set a green background color.
    <input type="text" id="demo"
           onkeydown=" = 'blue';"
           onkeyup=" = 'green';">



keyup event attribute


  • This example includes a styled header, sub-header, and an input field.
  • Utilizes onkeydown and onkeyup attributes within the input field.
  • Functions dynamically change the input field’s background color based on key events.

Example 2: In this example, we will see the implementation of onkeyup to display the text entered when the key is released.


<!DOCTYPE html>
                color: green;
                font-weight: bold;
            Key Release Example
        <label for="textInput">
            Type something:
            onkeyup="contentInfo.innerText = 'You typed: ' + this.value "
        <p id="contentInfo"></p>



HTML onkeyup Event Attribute

HTML onkeyup Event Attribute Use cases

1. How to check whether the enter key is pressed in a textbox or not using JavaScript / jQuery ?

In JavaScript, use the keyup event listener on the textbox, then check if the event’s keyCode or `key` property equals 13, indicating the Enter key press.

2. How to use keyup with delay in jQuery ?

In jQuery, use the keyup() function along with setTimeout() to introduce a delay. This delays execution of the specified function until after the key has been released for the defined duration.

Supported Browser

The browser supported by value attribute in option tag are listed below:

Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads