HTML Dialog Generator
WM-31Type a heading and your message, then copy a dialog element with a close button and an opener button. No library is needed: the browser handles focus and the Escape key for a modal dialog.
Runs in your browser. Nothing is uploaded.
Dialog text (required line: heading:; optional: close:, opener:, id:)
HTML
How to use it
- Write a heading: line and the dialog text; separate paragraphs with a blank line.
- Optionally add close: and opener: lines to set the button labels.
- Choose modal, non-modal or already open.
- Copy the markup into your page.
What showModal does
Calling showModal on a dialog opens it as a modal: the rest of the page cannot be clicked, a ::backdrop pseudo-element is drawn behind it, focus moves into the dialog, and the Escape key closes it. The show method opens it without those effects, so the page behind stays usable. Setting the open attribute also shows it non-modally, but MDN advises opening a modal through showModal rather than the attribute, which is why the open mode here is a separate choice.
How the close button works
The generated form uses method="dialog". Submitting a form like that closes the dialog without sending anything to a server, and the value of the submit button used becomes the dialog returnValue. You can read it in the close event. aria-labelledby ties the dialog to its h2, so assistive technology reads the heading as the dialog name. The tool adds no styling, no animation and no other script.
Error messages and what to do
| Message | What it means | Fix |
|---|---|---|
Add a "heading:" line. A dialog needs a title that names it. | No heading: line was found. | Add heading: followed by the dialog title. |
The dialog id can only use letters, digits, - and _, and must start with a letter. | The id: line held characters that are not allowed in the opener script. | Use a simple id such as confirm-delete. |
Questions people ask
How do I make a popup in HTML without JavaScript libraries?
Use a dialog element and call its showModal method from a button. The generated opener has a one-line onclick that does that, and the close button needs no script, since a form with method="dialog" closes it.
What is the difference between show and showModal?
showModal makes the page behind inert, draws a backdrop and lets Escape close the dialog. show opens it without blocking the page. Use modal when the user must answer before going on.
Why is my dialog not visible?
A dialog is hidden until it is opened. Either call showModal or show from script, or add the open attribute. The dialog element is closed by default, which is why the opener button is included.
How do I close an HTML dialog?
Call its close method, press Escape on a modal dialog, or submit a form with method="dialog" inside it. The generated Close button is a form submit of that kind, so no script is needed.
Is the dialog element accessible?
It has the dialog role built in and a modal one traps focus. It still needs a name, which is why the tool writes aria-labelledby pointing at the heading. Check that the first focusable control makes sense for your content.
About this tool
Writes a dialog with an h2 heading, one p per paragraph (separate paragraphs with a blank line), and a form with method="dialog" holding a close button; submitting that form closes the dialog. aria-labelledby points the dialog at its heading so it has an accessible name. Modal and non-modal modes add an opener button whose onclick calls showModal() or show(); the already-open mode only sets the open attribute and has no opener. The id (default dialog) must start with a letter and use only letters, digits, - or _. The tool writes no styles and no other script, and it does not return a value from the dialog.