Free Online CSS Modal Generator Built on dialog
Style a modal built on the real dialog element rather than a div with a z-index. Set the backdrop colour and blur, the panel width, padding, radius and shadow, the header, body and footer layout, the close button, and a fade, scale or slide entry animation with a duration you choose.
This is a real dialog opened with showModal. Press Escape to close it, and try pressing Tab while it is open: focus stays inside, and the page behind it cannot be reached.
Enjoying WizTools123? Help keep our server infrastructure 100% free and open for everyone.
How to Style a Modal with the dialog Element
A few steps, and nothing is uploaded.
What to Know About Modal Dialogs
Including what dialog does for you that a div cannot.
showModal() keeps focus inside the dialog, so Tab cycles within it instead of wandering off into the page behind. It closes on Escape with no key handler of your own. And it makes the rest of the document inert, so nothing behind the dialog can be clicked or read by assistive technology. That is the whole reason to use it: a div with a high z-index gives you none of those, and reimplementing them correctly is a surprising amount of code.
display: none to shown, and a transition has no starting value to work from, which is why naive fade in code does nothing. The generated CSS puts display and overlay in the transition with allow-discrete, and uses an @starting-style block for the values the dialog starts at. A plain @supports not fallback is written underneath so that in a browser without support the dialog simply appears, fully visible, rather than staying invisible.
show() and a hardcoded open attribute both display the dialog without the modal behaviour: there is no backdrop, focus is not contained, Escape does nothing and the page behind stays interactive. They are for non modal dialogs, which are a different thing. The snippet in the output uses showModal, and the close button calls close().
Key Features & Capabilities
What this tool does, and what it deliberately does not.
About the CSS Modal Generator
For years a modal meant a fixed position div, a second div for the shade behind it, a z-index chosen by argument, a key listener for Escape, a focus trap that was never quite right, and a scroll lock on the body. The <dialog> element replaces nearly all of that. It is now supported everywhere that matters, and once you open it with showModal() the browser handles the backdrop, the focus containment, the Escape key and making the rest of the page inert.
That leaves styling, which is what this page does. The preview is a real dialog: the button opens it with showModal, the close button calls close, Escape works because the browser makes it work, and the generated CSS is applied through a stylesheet in the page so the ::backdrop rule and the opening animation are the real thing rather than an impression of them.
The interesting problem is the animation. A dialog is display: none until it is open, and transitions do not run from a display change, so the usual fade in code silently does nothing. The fix is to put display and overlay in the transition with allow-discrete and to declare the opening values in an @starting-style block. Because that is recent, the tool also writes an @supports not fallback that leaves the dialog plainly visible, which is the right failure: a dialog that arrives without animation is fine, a dialog stuck at zero opacity is not.
Frequently Asked Questions
showModal, the backdrop, animating in and closing.
method="dialog" closes the dialog on submit and records which button was used in the returnValue. That is often exactly what a confirm dialog wants. Do keep the submit button inside the form, and remember the dialog closing does not itself submit anything to a server.