<dialog>
element
The
<dialog>
element isn't supported in your browser just yet, please use Chrome on desktop or a compatible mobile browser listed
here
.
Press the button below to toggle the
<dialog>
using the native JavaScript API. You can invoke the
<dialog>
by calling the
showModal()
(needed to show the backdrop pseudo element) or
show()
methods and can hide it by calling the
close()
method.
To work out if the
<dialog>
is visible on the screen the API adds a property to the
HTMLDialogElement
instance which is aptly named
open
. You may notice in this demo that I have opted to use an additional class for determining if the
<dialog>
is visible on the screen. The reason behind this is pretty simple and it's because the
showModal()
doesn't allow transitions (yet - maybe in the future) to run therefore it just appears.
In saying this, using classes can be more powerful as it gives us more finite control over how the
<dialog>
appears to the user.