HTML onkeydownEvent Attribute
Example
Execute a script when a key is pressed:
<input type="text" onkeydown="displayResult()">
Try it Yourself »
Browser Support
![]()
![]()
![]()
![]()
![]()
All major browsers support the onkeydown event attribute
Definition and Usage
The onkeydown attribute triggers when the user presses a key (on the keyboard).
Tip:The event trigger order related to the onkeydown event:
- onkeydown
- onkeypress
- onkeyup
Note:The onkeydown attribute cannot be used on the following elements: <base>, <bdo>, <br>, <head>, <html>, <iframe>, <meta>, <param>, <script>, <style>, or <title>.
Differences Between HTML 4.01 and HTML5
None.
Syntax
<element onkeydown="script">
Attribute Value
| Value | Description |
|---|---|
| script | Specifies the script to be executed when the onkeydown event is triggered. |
HTML Event Attributes Other Extensions