JavaScript onkeydown vs onkeypress vs onkeyup Event

You are Here:

JavaScript onkeydown vs onkeypress vs onkeyup Event

The onkeydown event occurs when the user presses a keyboard key.

The onkeypress event occurs when the user presses a key on the keyboard, which means this event occurs between onkeydown and onkeyup events.

The onkeyup event occurs when the user releases a key that was previously pressed (on the keyboard).

The order of execution as follows

  1. onkeydown
  2. onkeypress
  3. onkeyup

Warning: The onkeypress event is deprecated and is no longer recommended, use the onkeydown event instead.


HTML Online Editor
<!DOCTYPE html> <html> <body> <input type="text"> <script> var x = document.getElementsByTagName("input")[0]; function myKeyDown(){ console.log("keydown is executed"); } function myKeyPress(){ console.log("keypress is executed"); } function myKeyUp(){ console.log("keyup is executed"); } x.addEventListener("keydown", myKeyDown); x.addEventListener("keypress", myKeyPress); x.addEventListener("keyup", myKeyUp); </script> </body> </html>


Hi Developers, we almost covered 97% of JavaScript Tutorials with examples for quick and easy learning.

We are working to cover every Single Concept in JavaScript.

Please do google search for:

Join Our Channel

Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.

This channel is primarily useful for Full Stack Web Developer.

Share this Page

Meet the Author