`, ``, ``, `
Ev Onkeypress
## HTML onkeypress Event Attribute
The `onkeypress` event attribute fires when the user presses a key on the keyboard.
Historically, this event was used to capture character input. However, in modern web development, it has been deprecated in favor of other keyboard events. This guide covers its syntax, behavior, and modern alternatives.
---
## Browser Support
The `onkeypress` attribute is supported by all major browsers:
* Google Chrome
* Microsoft Edge / Internet Explorer
* Mozilla Firefox
* Apple Safari
* Opera
> **Note:** While browsers still support `onkeypress` for backwards compatibility, it is deprecated in modern web standards.
---
## Definition and Usage
The `onkeypress` attribute triggers a script when a key is pressed down.
### Keyboard Event Order
When a user presses and releases a key, three events fire in the following order:
1. **`onkeydown`**: Fires when the key is first pressed down.
2. **`onkeypress`**: Fires after `onkeydown` (only for keys that produce a character value).
3. **`onkeyup`**: Fires when the key is released.
### Key Differences & Limitations
* **Non-character keys:** The `onkeypress` event does not fire for modifier or non-printable keys (such as ALT, CTRL, SHIFT, ESC, or arrow keys) in most browsers. If you need to detect these keys, use **`onkeydown`** instead.
* **Unsupported Elements:** The `onkeypress` attribute cannot be used with the following HTML elements: ` `, ``, `
`, ``, ``, `
`, ``, ``, `
YouTip