Dialog Modal Native Show Modal
Create a native modal dialog using the dialog element with showModal and form method close for accessible interactions.
Code
<dialog id="confirm-dialog">
<form method="dialog">
<p>Are you sure you want to delete this item?</p>
<menu>
<button value="cancel">Cancel</button>
<button value="confirm" autofocus>Delete</button>
</menu>
</form>
</dialog>
<button onclick="document.getElementById('confirm-dialog').showModal()">
Delete item
</button>How the snippet works
The markup uses the semantic elements dialog instead of generic containers, giving assistive technology and search engines real structure without extra wiring.
<dialog> gives native modal semantics — focus trapping and Escape handling come for free.
Script and styles anchor onto ids confirm-dialog, so behavior and styling stay decoupled from the tag names.
Statements that matter
<dialog id="confirm-dialog">
<form method="dialog">
<p>Are you sure you want to delete this item?</p>
Interactive Tools for This Topic
JSON to Zod Schema ConverterInfer typed Zod z.object schemas from JSON payloads locally, supporting nested objects, merged array shapes, enums, nullable fields, and JSDoc comments.JSON Schema ValidatorValidate JSON data against a JSON Schema definition and get detailed error reports. Supports type checking, required fields, and common constraint validation.JSONL / NDJSON InspectorValidate NDJSON and JSON Lines line-by-line, pinpoint syntax errors by line number, analyze key frequencies and types, and export a pretty JSON array.Credit Card Brand DetectorIdentify the card network from a number's prefix and length, validate the Luhn checksum, and show a masked form and the issuer identification number.
FAQ
- Why semantic elements instead of divs?
- `<dialog>` expose document structure to assistive technology and search engines without ARIA or class-name conventions.
Report a problem with this exampleOpens a pre-filled issue on GitHub.