The New Dialog Element of HTML 5.2
The recent standard HTML 5.2 brings us a new element called <dialog>. This allows us to create modal dialog boxes which can be made interactive with a bit of JavaScript.
Using the element is very simple, with its basic form looking like this:
<dialog open="">
This is a dialog box!
</dialog>
The additional attribute “open” makes sure that the dialog box is actually displayed. Without the attribute, even opening the box would require you to use JavaScript. By default, without the use of CSS, the dialog box looks very unappealing.
It overlays the entire complete page content, places itself in the middle of the screen, framed by a black border, with a size determined by the content of the box. The overlay puts a so-called backdrop on the page, preventing any interaction with the content outside of the box.
Backdrop is new as well, and it is the name of the according pseudo-element::backdrop, which can be styled via CSS to make it transparent, colorful, or however you want to. The dialog itself is designed as usual, via CSS, just like any other element.
Within the dialogue element, use other HTML elements to structure your dialog box, and build it to match your requirements. Theoretically, there is no limit to your imagination.
However, without JavaScript, this element has little use, as only displaying a static open or closed dialog window is not very sensible. The JavaScript methods showModal() and close() allow you to control the previously mentioned attribute open.
The first method adds the attribute, opening the dialog box. The second method removes the attribute, closing the dialog box. We don't need more flexibility here anyways.