Make an animated modal dialog
Type what it says. Get a dialog that dims the page and glides in, with its code as HTML, CSS and JS or React.
- Free, no sign-up
- Runs in your browser
- HTML + CSS + JS, React
A title, then the message. Write [Cancel] [Delete] on its own line to name the buttons.
Nothing in mind? Try one:
How it works
- Type what it says. The first line is the title and the next lines are the message: "Delete this file? It can't be undone." A line like [Cancel] [Delete] names the buttons; otherwise the title's first word picks them, and a dialog that deletes something gets a red button.
- Try it. The preview is a real dialog in a phone-sized frame: press the button inside it, or "Open / close", to watch the page dim, the box arrive and its content follow. Every change you make plays again.
- Check it. The page checks the timing against the animation rules for modals (enter in 250 to 350 ms with ease-out, exit in about 200 ms with ease-in, backdrop fade 200 to 250 ms, content 50 to 100 ms after the box and 30 to 50 ms apart, a 0.5 to 0.7 dim and a slight blur) and the contrast of the text and the main button.
- Copy it. As HTML, CSS and JS, CSS only, HTML only, the JavaScript function that opens and closes the dialog, or a React component, or download a standalone .html page.
Questions
- How fast should a modal animate?
- The modals-dialogs skill brings a modal in over 250 to 350 ms with ease-out and takes it out faster, in about 200 ms with ease-in. The page behind dims over 200 to 250 ms, and the content follows the box 50 to 100 ms later, its items 30 to 50 ms apart.
- Is the dialog accessible?
- It is the native dialog element opened as a modal, so focus moves inside and stays there and the page behind cannot be used. It is labelled by its title and described by its message. Escape and the buttons close it, and focus goes back to the button that opened it. In a dialog that deletes something, focus starts on the safe button.
- What happens on a click outside?
- You choose. It either closes the dialog, or, when an answer is needed, the box shakes for 300 ms and stays open. Escape and the buttons always close it.
- Is anything uploaded?
- No. The dialog, the check and the code are made in your browser. The optional AI advice sends the settings, the dialog's words and your description, only when you press its button. If you sign in, the dialogs you copy or download are also kept in your SkillSafe account.
- Which browsers does it work in?
- Every current browser. The native dialog element works in Chrome and Edge 37 and later, Firefox 98 and later and Safari 15.4 and later; the blur behind the dialog needs backdrop-filter, and browsers without it simply skip the blur.