--- url: "https://web.dev/articles/is-it-modal" titulek: "Is it :modal? | Articles | web.dev" h1: "Is it :modal? Stay organized with collections Save and categorize content based on your preferences." popis: "This handy CSS pseudo-selector gives you a way to select elements that are modal." jazyk: "en" kanonicka: "https://web.dev/articles/is-it-modal" drobecky: ["Articles", "Is it :modal?"] zdroj: "live" wayback_snapshot: "" stazeno: "2026-09-14 00:56:47" znaku: 2498 slov: 375 kodovani: "iso-8859-2" sha256: "4bfa5e9972c73e82d50b263d091ae10fa4e353a2733e983850b10f368fb910b4" --- Is it :modal? Stay organized with collections Save and categorize content based on your preferences. This handy CSS pseudo-selector gives you a way to select elements that are modal. Jhey Tompkins This handy pseudo-selector gives you a way to select elements that are "modal", and to avoid managing classes in JavaScript by providing a way to detect modal elements. Browser Support 105 105 103 15.6 [Source](https://developer.mozilla.org/docs/Web/CSS/Reference/Selectors/:modal) Two types of elements are currently classed as `:modal`: Dialog elements using the `showModal` method. Elements that are in full-screen mode. How can you use it? This example sets the scale of all `` elements that are `:modal`. `dialog:modal { scale: 2; }` Consider this demo where you can show a `` in either "modal" or "non-modal" styles. When you show the "modal" version, it uses the `::backdrop` provided by the top layer. `dialog::backdrop { background: hsl(0 0% 10% / 0.5); }` But, for the non-modal version which doesn't have a `::backdrop`, a fake one gets created with the `::before` pseudo-element. It's lighter and doesn't blur the content behind it. You could combine with `:not` to detect a non-modal ``. `dialog[open]:not(:modal)::before { content: ""; position: fixed; height: 100vh; width: 100vw; top: 50%; left: 50%; background: hsl(0 0% 10% / 0.25); transform: translate3d(-50%, -50%, -1px); }` This will also work for elements that are in full-screen mode too. Consider this heading element made of spans. `

: m o d a l

` When the element is in full-screen mode, the spans will animate. `h1 span { animation: jump calc(var(--speed, 0) * 1s) calc(var(--index, 0) * 0.1s) infinite ease; } header:modal span { --speed: 0.75; } @keyframes jump { 50% { transform: translateY(-50%); } }` Except as otherwise noted, the content of this page is licensed under the [Creative Commons Attribution 4.0 License](https://creativecommons.org/licenses/by/4.0/), and code samples are licensed under the [Apache 2.0 License](https://www.apache.org/licenses/LICENSE-2.0). For details, see the [Google Developers Site Policies](https://developers.google.com/site-policies). Java is a registered trademark of Oracle and/or its affiliates. Last updated 2022-09-02 UTC.