Skip to content
Related Articles

Related Articles

HTML | onkeypress Attribute

Improve Article
Save Article
Like Article
  • Difficulty Level : Basic
  • Last Updated : 12 Aug, 2021

This attribute fires when a user presses a key on the Keyboard. This event attribute can not be used for all keys (e.g. ALT, CTRL, SHIFT, ESC) in all browsers.
Supported Tags: All HTML elements, EXCEPT:

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


<element onkeypress="script">

Attribute: The onkeydown attribute works for all keys in all browsers. The script will be run when onkeypress attribute call.
Note: The order of events that is related to the onkeypress events: 

  • onkeydown
  • onkeypress
  • onkeyup



<!DOCTYPE html>
        <title>onkeypress attribute</title>
            body {
            h1 {
        <h2>onkeypress attribute</h2>
        <input type="text" onkeypress="GeeksForGeeks()">
            function GeeksForGeeks() {
                alert("Welcome to GeeksForGeeks!");

Before click in the text box: 

After click on the text box: 

Supported Browsers: The browser supported by onkeypress event attribute are listed below: 

  • Google Chrome
  • Internet Explorer
  • Firefox
  • Opera
  • Apple Safari


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!