HTML onkeydown Event Attribute HTML Reference



Example

Execute a JavaScript when a user is pressing a key:

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

Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

1. 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:

  1. onkeydown
  2. onkeypress
  3. onkeyup

Note: The onkeydown attribute CANNOT be used with: <base>, <bdo>, <br>, <head>, <html>, <iframe>, <meta>, <param>, <script>, <style>, or <title>.


2. Differences Between HTML 4.01 and HTML5

None.


3. Syntax

<element onkeydown="script">

4. Attribute Values

Value Description
script The script to be run on onkeydown

Relative articles