Skip to content
The HTML Herbarium

/static/herbario/gamer/en/especime/dialog/

Menu

HTM-028 · Interactive

<dialog>

A modal box with its own focus, layer and backdrop.

It is the only specimen in this herbarium that needs JavaScript to flower. showModal() is what puts the dialog in the top layer, traps focus inside it, makes the rest of the page inert and switches on the ::backdrop pseudo-element. A <form method="dialog"> closes the box and returns the value of the button pressed.

Opened by the open attribute straight in the HTML, it exists and shows — but with no modality, no dimmed backdrop and no focus trap.

<dialog id="ficha">
  <form method="dialog">
    <p>Sheet HTM-028 taken out of the drawer.</p>
    <button value="ok">Put it back</button>
  </form>
</dialog>
{esc(legenda)}

Sheet HTM-028 taken out of the drawer.

Without showModal(): no top layer, no dimmed backdrop and no focus trap. The button, however, really does close it — that is what method="dialog" does on its own. Reload the page to bring the box back.

Half a living specimen · opened by attribute, it exists in the flow and nothing more