--- url: "https://www.w3.org/WAI/WCAG22/Techniques/html/H102" titulek: "H102: Creating modal dialogs with the HTML dialog element | WAI | W3C" h1: "Technique H102:Creating modal dialogs with the HTML dialog element" popis: "" jazyk: "en" kanonicka: "" drobecky: [] zdroj: "live" wayback_snapshot: "" stazeno: "2026-09-14 05:33:20" znaku: 7163 slov: 1020 kodovani: "utf-8" sha256: "424fbebe092900d81aa3af9424336c53d6feb8f30bc4bf110547d0c591648552" --- # Technique H102:Creating modal dialogs with the HTML `dialog` element ## About this Technique This technique relates to [2.4.3 Focus Order](https://www.w3.org/WAI/WCAG22/Understanding/focus-order) (**Sufficient** when used for changing a web page dynamically). This technique applies to HTML. Techniques are examples of ways to meet Web Content Accessibility Guidelines (WCAG). They are **not required** to meet WCAG. Content can satisfy the normative requirements of WCAG even if it does not use any of the documented techniques. See [About WCAG Techniques](https://www.w3.org/WAI/WCAG22/Techniques/about). ## Description Website authors often use modal dialogs to focus a user's attention on information, or a task-related activity beyond the scope of the primary page's content. Modal dialogs can be built in markup using [ARIA's dialog role and related attributes](https://www.w3.org/WAI/ARIA/apg/patterns/dialog-modal/), or the HTML's `dialog` element. As well as meeting [the first rule of ARIA](https://www.w3.org/TR/using-aria/#rule1), the HTML `dialog` element offers several advantages to its ARIA counterpart, with the browser handling these features: - keyboard focus is moved to the newly-opened modal `dialog` ; - keyboard focus returns to the invoking element (assuming the element is still on the page) when the modal `dialog` is closed; - keyboard focus is limited to the contents of the modal `dialog` and the browser's chrome (e.g., the browser-specific UI, such as the address bar, etc.); - the page's content 'outside' of the modal dialog becomes [inert](https://html.spec.whatwg.org/multipage/interaction.html#modal-dialogs-and-inert-subtrees) , resulting in the content becoming hidden from assistive technologies, and inoperable to all users, so long as the modal `dialog` remains open; - the use of the Escape key to close the modal `dialog` . This technique uses the HTML `dialog` element rather than a custom ARIA implementation, reducing the level of effort to create an accessible modal dialog. ## Examples ### Example 1: A dialog to sign up to a mailing list This is an example of using a modal `dialog` element to show a mailing-list sign-up form to a user. The main part of the page contains a `button` element that, when activated, invokes the modal `dialog`. The `button` uses the `type` attribute to tell the browser that this isn't a `submit` `button`. When the modal `dialog` is opened, the browser will treat all content outside of the modal dialog as inert, rendering it inoperable and hiding the content from assistive technology. For example, a screen reader will not be able to reach or announce any of the inert content. Additionally, because the page content is inert, keyboard focus will only be able to reach focusable elements within the `dialog` element, and the browser's controls. When invoked, the browser automatically sets focus to the first focusable element in the dialog's DOM. In this example the `h1` element will receive focus because it has a `tabindex="-1"` attribute. Note that, although the `dialog`'s close `button` is visibly before the `h1`, it is the last item in the `dialog`'s DOM. If the `button` was first, it would receive focus when dialog was opened. #### The HTML ```