VOOZH about

URL: https://www.geeksforgeeks.org/javascript/html-dom-onkeypress-event/

⇱ HTML DOM onkeypress Event - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

HTML DOM onkeypress Event

Last Updated : 12 Jul, 2025

The DOM onkeypress event in HTML occurs when a key is pressed by the user. Order of events related to the onkeypress event:

Supported HTML tags: All HTML elements, EXCEPT:

  • <base>
  • <bdo>
  • <br>
  • <head>
  • <html>
  • <iframe>
  • <meta>
  • <param>
  • <script>
  • <style>
  • <title>

Syntax:

  • In HTML:
<element onkeypress="myScript">
  • In JavaScript:
object.onkeypress = function(){myScript};
  • In JavaScript, using the addEventListener() method:
object.addEventListener("keypress", myScript);

Example: onkeypress Event using the addEventListener() method 

Output: 

👁 Image
 

Supported Browsers: The browsers supported by HTML DOM onkeypress Event are listed below:

  • Google Chrome
  • Internet Explorer
  • Firefox
  • Apple Safari
  • Opera
Comment
Article Tags: