``` --- ## Browser Support All"> ``` --- ## Browser Support All" />
Easy Tutorial
❮ Tag Figcaption Att Link Rel ❯

HTML onkeypress Event Attribute

HTML Event Attributes

Example

Run a script when a key is pressed:

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

Browser Support

All major browsers support the onkeypress event attribute.


Definition and Usage

The onkeypress attribute is triggered when a key is pressed.

Tip: The sequence of event triggers related to the onkeypress event:

Note: The onkeypress event does not trigger for all keys in all browsers (e.g., ALT, CTRL, SHIFT, ESC). If you only need to detect if a key has been pressed, use onkeydown instead, as onkeydown is triggered by all keys.

Note: The onkeypress attribute cannot be used with the following elements: <base>, <bdo>, <br>, <head>, <html>, <iframe>, <meta>, <param>, <script>, <style>, or <title>.


Differences Between HTML 4.01 and HTML5

None.


Syntax

Attribute Values

Value Description
script Script to be run when the onkeypress event is triggered.

❮ Tag Figcaption Att Link Rel ❯