Created
April 12, 2022 10:47
-
-
Save lovelymono/d6245c0d0959dfe50ca53f25546070df to your computer and use it in GitHub Desktop.
Native dialog in HTML
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- You can use JSBin: https://jsbin.com/xoketogeda/edit?html,output to play around with it. --> | |
<!-- The dialog element is specified in HTML specification, §4.11.4 "The dialog | |
element": https://html.spec.whatwg.org/multipage/interactive-elements.html#the-dialog-element. --> | |
<button onclick="document.querySelector('dialog').showModal()">Open dialog</button> | |
<dialog style="width: 50%;"> | |
<h1>Native <code><dialog></code></h1> | |
<p> | |
Yes, it's native! No third-party libraries needed, no fancy things with <code><div></code>s | |
and CSS! We only need some JavaScript to open it, closing can be done by the browser already: | |
</p> | |
<pre><code>document.querySelector('dialog').showModal()</code></pre> | |
<form method="dialog"> | |
<button>Close</button> | |
</form> | |
</dialog> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment