--- url: "https://web.dev/articles/building/a-dialog-component" titulek: "Building a dialog component | Articles | web.dev" h1: "Building a dialog component Stay organized with collections Save and categorize content based on your preferences." popis: "A foundational overview of how to build color-adaptive, responsive, and accessible mini and mega modals with the `` element." jazyk: "en" kanonicka: "https://web.dev/articles/building/a-dialog-component" drobecky: ["Articles", "Building a dialog component"] zdroj: "live" wayback_snapshot: "" stazeno: "2026-09-14 11:11:47" znaku: 33838 slov: 4794 kodovani: "iso-8859-2" sha256: "dbb2998b1a5a0deed2193972ba11c4124b1882d1ed47bc9b1cf415c2ea810809" --- Building a dialog component Stay organized with collections Save and categorize content based on your preferences. A foundational overview of how to build color-adaptive, responsive, and accessible mini and mega modals with the `` element. Adam Argyle In this post I want to share my thoughts on how to build color-adaptive, responsive, and accessible mini and mega modals with the `` element. [Try the demo](https://gui-challenges.web.app/dialog/dist/) and [view the source](https://github.com/argyleink/gui-challenges)! Demonstration of the mega and mini dialogs in their light and dark themes. If you prefer video, here's a YouTube version of this post: Overview The [``](https://developer.mozilla.org/docs/Web/HTML/Element/dialog) element is great for in-page contextual information or action. Consider when the user experience can benefit from a same page action instead of multi-page action: perhaps because the form is small or the only action required from the user is confirm or cancel. The `` element has recently become stable across browsers: Browser Support 37 79 98 15.4 [Source](https://developer.mozilla.org/docs/Web/HTML/Reference/Elements/dialog) I found the element was missing a few things, so in this [GUI Challenge](https://a.nerdy.dev/gui-challenges) I add the developer experience items I expect: additional events, light dismiss, custom animations, and a mini and mega type. Markup The essentials of a `` element are modest. The element will automatically be hidden and has styles built in to overlay your content. ` … ` We can improve this baseline. Traditionally, a dialog element shares a lot with a modal, and often the names are interchangeable. I took the liberty here of using the dialog element for both small dialog popups (mini), as well as full page dialogs (mega). I named them mega and mini, with both dialogs slightly adapted for different use cases. I added a `modal-mode` attribute to allow you to specify the type: ` ` Not always, but generally dialog elements will be used to gather some interaction information. [Forms inside dialog elements are made to go together](https://developer.mozilla.org/docs/Web/API/HTMLDialogElement/returnValue). It's a good idea to have a form element wrap your dialog content so that JavaScript can access the data the user has entered. Furthermore, buttons inside a form using `method="dialog"` can close a dialog without JavaScript and pass data. `
…
` Mega dialog A mega dialog has three elements inside the form: [`
`](https://developer.mozilla.org/docs/Web/HTML/Element/header), [`
`](https://developer.mozilla.org/docs/Web/HTML/Element/article), and [`