HTML DOM onkeypress Event Last Updated : 12 Jul, 2025 Comments Improve Suggest changes Like Article Like Report The DOM onkeypress event in HTML occurs when a key is pressed by the user. Order of events related to the onkeypress event: onkeydownonkeypressonkeyup 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 HTML <!DOCTYPE html> <html> <head> <title> DOM onkeypress event </title> </head> <body> <h1 style="color:green"> GeekforGeeks </h1> <p> Press any key inside the input field. </p> <input type="text" id="inputField" style="background-color:green"> <script> document.getElementById( "inputField").addEventListener("keypress", GFGFun); function GFGFun() { document.getElementById( "inputField").style.backgroundColor = "yellow"; } </script> </body> </html> Output: Supported Browsers: The browsers supported by HTML DOM onkeypress Event are listed below: Google ChromeInternet ExplorerFirefoxApple SafariOpera Comment More infoAdvertise with us Next Article HTML DOM onkeyup Event V Vijay Sirra Follow Improve Article Tags : JavaScript Web Technologies HTML-DOM Similar Reads HTML DOM onkeyup Event The HTML DOM onkeyup event in HTML occurs when a key is released after pressing by the user. Order of events related to the onkeyup event. onkeydownonkeypressonkeyup Syntax: In HTML:<element onkeyup="myScript">In JavaScript:object.onkeyup = function(){myScript};In JavaScript, using the addEven 2 min read HTML DOM onkeyup Event The HTML DOM onkeyup event in HTML occurs when a key is released after pressing by the user. Order of events related to the onkeyup event. onkeydownonkeypressonkeyup Syntax: In HTML:<element onkeyup="myScript">In JavaScript:object.onkeyup = function(){myScript};In JavaScript, using the addEven 2 min read HTML DOM onkeyup Event The HTML DOM onkeyup event in HTML occurs when a key is released after pressing by the user. Order of events related to the onkeyup event. onkeydownonkeypressonkeyup Syntax: In HTML:<element onkeyup="myScript">In JavaScript:object.onkeyup = function(){myScript};In JavaScript, using the addEven 2 min read HTML DOM onkeyup Event The HTML DOM onkeyup event in HTML occurs when a key is released after pressing by the user. Order of events related to the onkeyup event. onkeydownonkeypressonkeyup Syntax: In HTML:<element onkeyup="myScript">In JavaScript:object.onkeyup = function(){myScript};In JavaScript, using the addEven 2 min read HTML DOM onkeydown Event The DOM onkeydown event in HTML occurs when a key is pressed by the user. Order of events related to the onkeydown event: onkeydownonkeypressonkeyup Supported HTML tags: All HTML elements, EXCEPT: <base><bdo><br><head><html><iframe><meta><param><scr 1 min read HTML DOM onkeydown Event The DOM onkeydown event in HTML occurs when a key is pressed by the user. Order of events related to the onkeydown event: onkeydownonkeypressonkeyup Supported HTML tags: All HTML elements, EXCEPT: <base><bdo><br><head><html><iframe><meta><param><scr 1 min read Like