Other delightfully interactive HTML elements include…<p>File pickers:<p><pre><code> <input type="file">
</code></pre>
Color pickers:<p><pre><code> <input type="color">
</code></pre>
Date/time pickers:<p><pre><code> <input type="month">
<input type="date">
<input type="time">
<input type="datetime-local">
</code></pre>
Numeric sliders:<p><pre><code> <input type="range" min="0" max="5">
</code></pre>
Suggested options for text fields:<p><pre><code> <input list="fonts">
<datalist id="fonts">
<option value="Courier New"></option>
<option value="Garamond"></option>
<option value="Georgia"></option>
<option value="Tahoma"></option>
<option value="Times New Roman"></option>
</datalist>
</code></pre>
Summaries with expandable details:<p><pre><code> <h2>FAQs</h2>
<details name="faq">
<summary>Why are interactive HTML elements cool?</summary>
They’re lightweight and semantic!
</details>
<details name="faq">
<summary>Will the previous answer close when I open this one?</summary>
Yes, because the <code>&lt;details&gt;</code> elements share the same name.
</details>
</code></pre>
Media players with controls:<p><pre><code> <audio controls src="example.mp3"></audio>
<video controls src="example.mp4"></video></code></pre>
I started using <dialog> in 2019, even though Firefox and Safari wouldn't support it for another couple of years, but Google's own Polyfill (of which I am a very modest contributor) was top-notch quality and so I had no problems using it in production for my LoB SaaS day-job.<p>But my biggest let-down with the <dialog> element is that it's comnpletely unstyled, beyond a very basic (and very un-Chrome-like) thick black line pixel border with sharp edges. Whereas my-hope-and-expectation (and indeed: what got me interested in <dialog> in the first place) was that I was hoping that the browser itself would provide for a lot of the tedium involved in UI dialog dev-work in-general, especially for things like automaticallyt conforming to the host OS' conventions on dialog/window layout and placement: I was hoping that I could mark-up an actual semantic model of a dialog and the browser would do the hard-work of making it look like a real native macOS (or iOS) - or Windows - dialog resource.<p>I was also hoping that, because open <dialog> elements exist in a distinct top-level layer, that they might even able to escape the bounds of the browser viewport, which would provide real value to the end-user in a lot of places (e.g. no-one wants an unmovable popup or modal-dialog that completely obscures the user's view of an underlying document (like macOS's old "Sheets" dialogs) - so another false-hope of mine got popped that day.<p>-----<p>I get the feeling that browser vendors would all like to see us stop using `alert()`, `prompt()` and `confirm()` in JavaScript (because they block the JS/main thred), but the same browser-vendors really haven't come-up with an adequate replacement: the beeauty of alert/prompt/confirm is that their API is incredibly simple yet effective and also doesn't require the proggrammer to have any UI design-skills; I don't understand why browsers still don't offer a non-blocking Promie-based API for alert/prompt/confirm instead of them trying, in vain, to convince us that <dialog> is better in every situastion when it clearly isn't.
]
See my article "The HTML dialog element API is a mess": <a href="https://lapcatsoftware.com/articles/2024/2/1.html" rel="nofollow">https://lapcatsoftware.com/articles/2024/2/1.html</a>
Regardless of the implementation I think this was a step in the right direction.<p>There's a <i><combobox></i> proposal in the works which is like a <i><select></i> on steroids [1].<p>Also the Popover API [1] already in browsers for toast alerts. And a popover hint proposal for tooltips[2].<p>[1] <a href="https://open-ui.org/components/combobox.explainer/" rel="nofollow">https://open-ui.org/components/combobox.explainer/</a><p>[2] <a href="https://mdn.github.io/dom-examples/popover-api/" rel="nofollow">https://mdn.github.io/dom-examples/popover-api/</a><p>[3] <a href="https://open-ui.org/components/popover-hint.research.explainer/" rel="nofollow">https://open-ui.org/components/popover-hint.research.explain...</a>
I love the <dialog> element, especially for its built-in / standardised accessibility considerations. I'm looking forward to the day I can roll it without a polyfill (once safari <15.4 drops out of our thresholds).<p>That said, my one major bugbear with it is the reliance on javascript. Yep, I expect all* users on my sites to arrive with JS enabled. But I also (selfishly?) derive some satisfaction from them not having to. Why can't I control the dialog's open state with CSS or a targeted button?<p>Would love to learn I'm wrong about this.
I wish HTML supported a concept of a "<PAGE>" tag which will allow multiple pages to be defined in a single HTML file and which can be shown one at a time but without the look-and-feel of a dialog.<p>Each PAGE should be able to pull in common sections from the same page such as the header, sidebar, footer etc based on specific states selectable in each PAGE.<p>Yes, you can do the same thing with the current approaches by hiding and showing divs etc.. But if it were possible to support these approaches via specific tags in HTML it may help.<p>EXAMPLE:<p><pre><code> <COMMON>
<script>
.. common javascript elements here
</script>
<SECTION id="header">
...
</SECTION>
<SECTION id="sidebar">
...
</SECTION>
<SECTION id="footer">
...
</SECTION>
</COMMON>
<PAGE default name="Home">
<INCLUDE from="header"/>
<INCLUDE from="sidebar"/>
<DIV>
.....
</DIV>
<INCLUDE from="footer"/>
</PAGE>
<PAGE name="Login">
<INCLUDE from="header"/>
<DIV>
.....
</DIV>
<INCLUDE from="footer"/>
</PAGE>
<PAGE name="Profile">
<INCLUDE from="header"/>
<INCLUDE from="sidebar"/>
<DIV>
.....
</DIV>
<INCLUDE from="footer"/>
</PAGE></code></pre>
Tried this today and came across an issue that I could not get around: if the dialog contains a form, then submitting the form with enter (focused on any input) or space (focused on the submit button) will close the dialog. I couldn't find any nice way of preventing it.<p>Normally a form will reload the page anyways so I guess this isn't a normal problem but I was using htmx.
I was unfortunately looking for a cookie consent manager for a new build I'd just optimized, and didn't like that the open source options were 100KB+ so I made my own [0] and relied on <dialog> to support my goal of writing it as small as possible. With a couple of CSS rules, it works natively without styles. I also ended up writing some build tools to compile all the way down to IE11 and some really ancient browser versions.<p>Dialog works well for the most part, with a couple of CSS kludges here and there for the older browsers but otherwise straightforward to deal with. It's a decent addition to the web platform, but after 20 years of this I would like to stop making custom multi select controls every couple of years. Native controls good.<p>[0]: <a href="https://github.com/replete/biscuitman">https://github.com/replete/biscuitman</a>
The worst thing about `<dialog>` is that modal ones are placed in the CSS "top layer" which obstructs portalled content like tooltips and dropdowns.
>Note: While you can toggle between the open and closed states of non-modal dialog boxes by toggling the presence of the open attribute, this approach is not recommended.<p>This perplexes me. Why is it not recommended? Why put it in a standard and then recommend against it? What's wrong with it? The documentation is silent.
Ublock origin is not able to filter out <dialog> elements without breaking scrolling and other buttons in most cases (depending on how the site is implemented). Is there a generic way to disable these without affecting the rest of the site?
I'm really glad you posted this 'htunnicliff', because I'm manually maintaining a 'stack' of Dialog elements, along with an associated full-bleed 'background' overlay to block mouse clicks outside the dialog, and it will be really nice if I can get this (dialog element) to work and replace my code with something simpler. I'm assuming dialog elements can overlay other dialog elements!! I'll try!
I still remember being confused about the differences between dialogs, popovers, and modal vs non-modal elements when I was first learning web development.
About two years year before <dialog> was rushed into all browsers, it had been implemented only in Chrome, and Chrome devs suggested removal of <dialog> completely. Reason? No consensus on multiple issues relating to accessibility and security: <a href="https://github.com/whatwg/html/pull/4184#issuecomment-440405059">https://github.com/whatwg/html/pull/4184#issuecomment-440405...</a><p>And then boom! It was shipped everywhere with none of the issues discussed or fixed.<p>Why?<p>My tiny conspiracy theory is because browsers are hellbent on removing "legacy" APIs like confirm/prompt, and Chrome tried to remove it about half-a-year to a year before <dialog> was suddenly shipped everywhere: <a href="https://dev.to/richharris/stay-alert-d" rel="nofollow">https://dev.to/richharris/stay-alert-d</a>
The dialog tag is not a good idea - it can still be used to completely force a user into clicking and forcing an action they can't control<p><a href="https://tane.dev/2021/02/revisiting-dark-patterns-with-the-html-dialog-tag/" rel="nofollow">https://tane.dev/2021/02/revisiting-dark-patterns-with-the-h...</a>
I got an issue recently with how <dialog> interacts with AdSense “vignette” (interstitial) ads.<p>Vignettes set their `z-index` CSS property to the max (2147483647), but a <dialog> is still higher on the z-plane (with no way to adjust that).<p>So if you click a link from a <dialog>, and an interstitial gets displayed, it’s <i>under</i> the <dialog>. It looks like nothing happened, that clicking is broken.<p>Fix in my case was to close() the <dialog> onclick.