TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

<dialog>: The Dialog Element

329 pointsby htunnicliff5 months ago

18 comments

divbzero5 months ago
Other delightfully interactive HTML elements include…<p>File pickers:<p><pre><code> &lt;input type=&quot;file&quot;&gt; </code></pre> Color pickers:<p><pre><code> &lt;input type=&quot;color&quot;&gt; </code></pre> Date&#x2F;time pickers:<p><pre><code> &lt;input type=&quot;month&quot;&gt; &lt;input type=&quot;date&quot;&gt; &lt;input type=&quot;time&quot;&gt; &lt;input type=&quot;datetime-local&quot;&gt; </code></pre> Numeric sliders:<p><pre><code> &lt;input type=&quot;range&quot; min=&quot;0&quot; max=&quot;5&quot;&gt; </code></pre> Suggested options for text fields:<p><pre><code> &lt;input list=&quot;fonts&quot;&gt; &lt;datalist id=&quot;fonts&quot;&gt; &lt;option value=&quot;Courier New&quot;&gt;&lt;&#x2F;option&gt; &lt;option value=&quot;Garamond&quot;&gt;&lt;&#x2F;option&gt; &lt;option value=&quot;Georgia&quot;&gt;&lt;&#x2F;option&gt; &lt;option value=&quot;Tahoma&quot;&gt;&lt;&#x2F;option&gt; &lt;option value=&quot;Times New Roman&quot;&gt;&lt;&#x2F;option&gt; &lt;&#x2F;datalist&gt; </code></pre> Summaries with expandable details:<p><pre><code> &lt;h2&gt;FAQs&lt;&#x2F;h2&gt; &lt;details name=&quot;faq&quot;&gt; &lt;summary&gt;Why are interactive HTML elements cool?&lt;&#x2F;summary&gt; They’re lightweight and semantic! &lt;&#x2F;details&gt; &lt;details name=&quot;faq&quot;&gt; &lt;summary&gt;Will the previous answer close when I open this one?&lt;&#x2F;summary&gt; Yes, because the &lt;code&gt;&amp;lt;details&amp;gt;&lt;&#x2F;code&gt; elements share the same name. &lt;&#x2F;details&gt; </code></pre> Media players with controls:<p><pre><code> &lt;audio controls src=&quot;example.mp3&quot;&gt;&lt;&#x2F;audio&gt; &lt;video controls src=&quot;example.mp4&quot;&gt;&lt;&#x2F;video&gt;</code></pre>
评论 #42348831 未加载
评论 #42349077 未加载
评论 #42350516 未加载
DaiPlusPlus5 months ago
I started using &lt;dialog&gt; in 2019, even though Firefox and Safari wouldn&#x27;t support it for another couple of years, but Google&#x27;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 &lt;dialog&gt; element is that it&#x27;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 &lt;dialog&gt; 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&#x27; conventions on dialog&#x2F;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 &lt;dialog&gt; 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&#x27;s view of an underlying document (like macOS&#x27;s old &quot;Sheets&quot; 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&#x2F;main thred), but the same browser-vendors really haven&#x27;t come-up with an adequate replacement: the beeauty of alert&#x2F;prompt&#x2F;confirm is that their API is incredibly simple yet effective and also doesn&#x27;t require the proggrammer to have any UI design-skills; I don&#x27;t understand why browsers still don&#x27;t offer a non-blocking Promie-based API for alert&#x2F;prompt&#x2F;confirm instead of them trying, in vain, to convince us that &lt;dialog&gt; is better in every situastion when it clearly isn&#x27;t. ]
评论 #42343803 未加载
评论 #42346289 未加载
评论 #42343927 未加载
评论 #42344829 未加载
评论 #42346800 未加载
评论 #42344984 未加载
评论 #42346840 未加载
评论 #42344567 未加载
评论 #42346171 未加载
评论 #42351655 未加载
评论 #42346082 未加载
评论 #42348754 未加载
评论 #42346935 未加载
评论 #42352746 未加载
评论 #42343601 未加载
评论 #42344885 未加载
评论 #42344987 未加载
lapcat5 months ago
See my article &quot;The HTML dialog element API is a mess&quot;: <a href="https:&#x2F;&#x2F;lapcatsoftware.com&#x2F;articles&#x2F;2024&#x2F;2&#x2F;1.html" rel="nofollow">https:&#x2F;&#x2F;lapcatsoftware.com&#x2F;articles&#x2F;2024&#x2F;2&#x2F;1.html</a>
评论 #42344225 未加载
评论 #42346124 未加载
评论 #42351396 未加载
评论 #42344493 未加载
pier255 months ago
Regardless of the implementation I think this was a step in the right direction.<p>There&#x27;s a <i>&lt;combobox&gt;</i> proposal in the works which is like a <i>&lt;select&gt;</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:&#x2F;&#x2F;open-ui.org&#x2F;components&#x2F;combobox.explainer&#x2F;" rel="nofollow">https:&#x2F;&#x2F;open-ui.org&#x2F;components&#x2F;combobox.explainer&#x2F;</a><p>[2] <a href="https:&#x2F;&#x2F;mdn.github.io&#x2F;dom-examples&#x2F;popover-api&#x2F;" rel="nofollow">https:&#x2F;&#x2F;mdn.github.io&#x2F;dom-examples&#x2F;popover-api&#x2F;</a><p>[3] <a href="https:&#x2F;&#x2F;open-ui.org&#x2F;components&#x2F;popover-hint.research.explainer&#x2F;" rel="nofollow">https:&#x2F;&#x2F;open-ui.org&#x2F;components&#x2F;popover-hint.research.explain...</a>
somishere5 months ago
I love the &lt;dialog&gt; element, especially for its built-in &#x2F; standardised accessibility considerations. I&#x27;m looking forward to the day I can roll it without a polyfill (once safari &lt;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&#x27;t I control the dialog&#x27;s open state with CSS or a targeted button?<p>Would love to learn I&#x27;m wrong about this.
评论 #42348814 未加载
评论 #42356944 未加载
pkphilip5 months ago
I wish HTML supported a concept of a &quot;&lt;PAGE&gt;&quot; 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> &lt;COMMON&gt; &lt;script&gt; .. common javascript elements here &lt;&#x2F;script&gt; &lt;SECTION id=&quot;header&quot;&gt; ... &lt;&#x2F;SECTION&gt; &lt;SECTION id=&quot;sidebar&quot;&gt; ... &lt;&#x2F;SECTION&gt; &lt;SECTION id=&quot;footer&quot;&gt; ... &lt;&#x2F;SECTION&gt; &lt;&#x2F;COMMON&gt; &lt;PAGE default name=&quot;Home&quot;&gt; &lt;INCLUDE from=&quot;header&quot;&#x2F;&gt; &lt;INCLUDE from=&quot;sidebar&quot;&#x2F;&gt; &lt;DIV&gt; ..... &lt;&#x2F;DIV&gt; &lt;INCLUDE from=&quot;footer&quot;&#x2F;&gt; &lt;&#x2F;PAGE&gt; &lt;PAGE name=&quot;Login&quot;&gt; &lt;INCLUDE from=&quot;header&quot;&#x2F;&gt; &lt;DIV&gt; ..... &lt;&#x2F;DIV&gt; &lt;INCLUDE from=&quot;footer&quot;&#x2F;&gt; &lt;&#x2F;PAGE&gt; &lt;PAGE name=&quot;Profile&quot;&gt; &lt;INCLUDE from=&quot;header&quot;&#x2F;&gt; &lt;INCLUDE from=&quot;sidebar&quot;&#x2F;&gt; &lt;DIV&gt; ..... &lt;&#x2F;DIV&gt; &lt;INCLUDE from=&quot;footer&quot;&#x2F;&gt; &lt;&#x2F;PAGE&gt;</code></pre>
评论 #42348209 未加载
andypants5 months ago
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&#x27;t find any nice way of preventing it.<p>Normally a form will reload the page anyways so I guess this isn&#x27;t a normal problem but I was using htmx.
评论 #42344476 未加载
评论 #42344995 未加载
评论 #42346145 未加载
replete5 months ago
I was unfortunately looking for a cookie consent manager for a new build I&#x27;d just optimized, and didn&#x27;t like that the open source options were 100KB+ so I made my own [0] and relied on &lt;dialog&gt; 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&#x27;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:&#x2F;&#x2F;github.com&#x2F;replete&#x2F;biscuitman">https:&#x2F;&#x2F;github.com&#x2F;replete&#x2F;biscuitman</a>
评论 #42348987 未加载
评论 #42349058 未加载
Sateeshm5 months ago
Normal close in most examples not working for me. Android Firefox
评论 #42349301 未加载
评论 #42345831 未加载
评论 #42344057 未加载
silverwind5 months ago
The worst thing about `&lt;dialog&gt;` is that modal ones are placed in the CSS &quot;top layer&quot; which obstructs portalled content like tooltips and dropdowns.
评论 #42346170 未加载
poincaredisk5 months ago
&gt;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&#x27;s wrong with it? The documentation is silent.
srathi5 months ago
Ublock origin is not able to filter out &lt;dialog&gt; 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?
评论 #42349328 未加载
quantadev5 months ago
I&#x27;m really glad you posted this &#x27;htunnicliff&#x27;, because I&#x27;m manually maintaining a &#x27;stack&#x27; of Dialog elements, along with an associated full-bleed &#x27;background&#x27; 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&#x27;m assuming dialog elements can overlay other dialog elements!! I&#x27;ll try!
评论 #42345577 未加载
评论 #42346923 未加载
joshdavham5 months ago
I still remember being confused about the differences between dialogs, popovers, and modal vs non-modal elements when I was first learning web development.
troupo5 months ago
About two years year before &lt;dialog&gt; was rushed into all browsers, it had been implemented only in Chrome, and Chrome devs suggested removal of &lt;dialog&gt; completely. Reason? No consensus on multiple issues relating to accessibility and security: <a href="https:&#x2F;&#x2F;github.com&#x2F;whatwg&#x2F;html&#x2F;pull&#x2F;4184#issuecomment-440405059">https:&#x2F;&#x2F;github.com&#x2F;whatwg&#x2F;html&#x2F;pull&#x2F;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 &quot;legacy&quot; APIs like confirm&#x2F;prompt, and Chrome tried to remove it about half-a-year to a year before &lt;dialog&gt; was suddenly shipped everywhere: <a href="https:&#x2F;&#x2F;dev.to&#x2F;richharris&#x2F;stay-alert-d" rel="nofollow">https:&#x2F;&#x2F;dev.to&#x2F;richharris&#x2F;stay-alert-d</a>
评论 #42345348 未加载
tanepiper5 months ago
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&#x27;t control<p><a href="https:&#x2F;&#x2F;tane.dev&#x2F;2021&#x2F;02&#x2F;revisiting-dark-patterns-with-the-html-dialog-tag&#x2F;" rel="nofollow">https:&#x2F;&#x2F;tane.dev&#x2F;2021&#x2F;02&#x2F;revisiting-dark-patterns-with-the-h...</a>
评论 #42351156 未加载
palsecam5 months ago
I got an issue recently with how &lt;dialog&gt; interacts with AdSense “vignette” (interstitial) ads.<p>Vignettes set their `z-index` CSS property to the max (2147483647), but a &lt;dialog&gt; is still higher on the z-plane (with no way to adjust that).<p>So if you click a link from a &lt;dialog&gt;, and an interstitial gets displayed, it’s <i>under</i> the &lt;dialog&gt;. It looks like nothing happened, that clicking is broken.<p>Fix in my case was to close() the &lt;dialog&gt; onclick.
评论 #42346060 未加载
评论 #42343970 未加载
ulrischa5 months ago
Why is this on the front page? It is nothing special
评论 #42344170 未加载
评论 #42343651 未加载
评论 #42343650 未加载
评论 #42345061 未加载
评论 #42344583 未加载