HTML onkeydown event attribute

Example

When the user presses a key, execute a JavaScript block:

<input type="text"> onkeydown="displayResult()">

Try It Yourself

Browser Support

IE Firefox Chrome Safari Opera

All major browsers support the onkeydown attribute.

Definition and Usage

The onkeydown attribute triggers when the user (on the keyboard) presses a key.

Tip:The event order relative to onkeydown events:

  • onkeydown
  • onkeypress
  • onkeyup

Note:The onkeydown attribute is not applicable to 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 Script executed when onkeydown occurs.