Escape
27
escape
event.keyCode
27
event.key
Escape
event.code
Escape
Unicode
⎋
Code Examples
Copy and paste these examples to detect the Escape key in your JavaScript code
Recommended modern approach
// Modern approach (recommended)
document.addEventListener('keydown', (e) => {
if (e.key === 'Escape') {
console.log('Escape key pressed!');
// Your code here
}
});Common Use Cases
How the Escape key is typically used in web applications
Close Modals
Close popup dialogs, overlays, and modal windows
Cancel Actions
Cancel in-progress operations or exit edit modes
Clear Search
Clear search inputs and reset filters
Exit Fullscreen
Exit fullscreen mode in media players
Related Keys
Other keys commonly used together or in similar contexts