Stop russian invasion of Ukraine 🇺🇦

Closing modal window on the ESC button

Closing modal window on the ESC button

It’s time to improve the accessibility of modal dialogs too! Add an event listener that waits when the ESC button is pressed and then runs the same action as the .modal__closeclass:

// close CTA section on the ESC button
document.body.addEventListener('keydown', function (e) {
  if (e.key === 'Escape') {

Try it live on this example

It might be interesting for you

Let’s create together

Start a project

Let’s create together

What are your interested in?



Personal details

Thank you for getting in touch!
We appreciate you contacting us.
We will get back to you shortly.
Something went wrong while submitting the form.