Native <dialog> · Vanilla JS · 0 libraries

Click it. Pop!
A window appears.

A small study of the modal window: the box that pops up on top of a page, waits for your answer and then politely disappears. It closes with Esc, the × button or a click outside.

View the code
3 ways to close
3 modal examples
0 dependencies
100% keyboard friendly

Try three kinds of modals

info.window

Say hello

The classic: a short message and one way out. This is the original version of the project.

confirm.window

Are you sure?

A confirm dialog with two choices. Focus starts on the safe button.

form.window

Join the list

A modal with a real form, a label and validation. Nothing is sent anywhere.

How it works

  1. The browser does the hard part

    dialog.showModal() puts the window on top, keeps the focus inside it and makes Esc close it.

  2. A click outside closes it

    If the click lands on the dialog itself and not on its content, it was on the dark backdrop, so we close.

  3. CSS makes it pop

    The window grows from 92% to 100% and fades in. Only transform and opacity move, so it stays smooth.