HTML onkeydown Event Attribute Last Updated : 11 Jul, 2025 Comments Improve Suggest changes Like Article Like Report The onkeydown event attribute works when the user presses any key from the keyboard. The onkeydown event is triggered when the down key is pressed down and used for capturing and responding to key events. Syntax: <element onkeydown = "script">Supported Tags: It supports all HTML elements EXCEPT- <base> <bdo> <br> <head> <html> <iframe> <meta> <param> <script> <style> <title>Attribute Value: This attribute contains single value script which works when any key pressed from the keyboard. Example 1: In this example we will see the implementation of onkeydown tag. html <!DOCTYPE html> <html> <head> <title> HTML | onkeydown Event Attribute </title> <style> h1 { text-align: center; color: green; } h2 { text-align: center; } input[type=text] { width: 100%; padding: 12px 20px; margin: 8px 0; box-sizing: border-box; font-size: 24px; color: white; } p { font-size: 20px; } </style> </head> <body> <h1>GeeksforGeeks</h1> <h2>onkeyup Event Attribute</h2> <p> Release the key to set a green background color. </p> <input type="text" id="demo" onkeydown="keydownFunction()" onkeyup="keyupFunction()"> <script> function keyupFunction() { document.getElementById("demo"). style.backgroundColor = "blue"; } function keydownFunction() { document.getElementById("demo"). style.backgroundColor = "green"; } </script> </body> </html> Output: OutputExample 2: In this example we will see the implementation of onkeydown tag. HTML <!DOCTYPE html> <html> <body> <center> <h1 style="color:purple;font-weight:bold;"> Key Press Example </h1> <p> Press a key: </p> <input type="text" onkeydown="showKeyPress(event)"> <p id="keyInfo"></p> <script> function showKeyPress(event) { var keyInfo = "Key Pressed: " + event.key; document.getElementById("keyInfo"). innerHTML = keyInfo; } </script> </center> </body> </html> Output: OutputSupported Browser: Google Chrome 1 and aboveEdge 12 and aboveFirefox 6 and aboveOpera 12.1 and aboveSafari 1.2 and above Create Quiz Comment V Vishal Chaudhary 2 Follow 0 Improve V Vishal Chaudhary 2 Follow 0 Improve Article Tags : Web Technologies HTML HTML-Attributes Explore HTML BasicsHTML Introduction4 min readHTML Editors4 min readHTML Basics7 min readStructure & ElementsHTML Elements4 min readHTML Attributes7 min readHTML Headings3 min readHTML Paragraphs3 min readHTML Text Formatting4 min readHTML Block and Inline Elements3 min readHTML Charsets4 min readListsHTML Lists3 min readHTML Ordered Lists5 min readHTML Unordered Lists4 min readHTML Description Lists3 min readVisuals & MediaHTML Colors11 min readHTML Links Hyperlinks2 min readHTML Images7 min readHTML Favicon4 min readHTML Video4 min readLayouts & DesignsHTML Tables9 min readHTML Iframes4 min readHTML Layout4 min readHTML File Paths3 min readProjects & Advanced TopicsHTML Forms4 min readHTML5 Semantics5 min readHTML URL Encoding4 min readHTML Responsive Web Design11 min readTop 10 Projects For Beginners To Practice HTML and CSS Skills8 min readTutorial ReferencesHTML Tags - A to Z List5 min readHTML Attributes Complete Reference8 min readHTML Global Attributes5 min readHTML5 Complete Reference8 min readHTML5 MathML Complete Reference3 min readHTML DOM Complete Reference15+ min readHTML DOM Audio/Video Complete Reference2 min readSVG Element Complete Reference5 min readSVG Attribute Complete Reference8 min readSVG Property Complete Reference7 min readHTML Canvas Complete Reference4 min read Like