HTML onkeydown Attribute
Definition and Usage
The onkeydown attribute fires when the user is pressing a key (on the keyboard).
Tip: The order of events related to the onkeydown event:
- onkeydown
- onkeypress
- onkeyup
Applies to
The onkeydown attribute is part of the Event Attributes, and can be used on any HTML elements.
Elements | Event |
---|---|
All HTML elements | onkeydown |
Example
Input Example
Execute a JavaScript when a user is pressing a key:
<input type="text" onkeydown="myFunction()">
Try it Yourself »
Browser Support
Event Attribute | |||||
---|---|---|---|---|---|
onkeydown | Yes | Yes | Yes | Yes | Yes |