::backdrop
Example
.overlay {
position: fixed;
inset: 0;
background: rgb(0 0 0 / 50%);
}dialog::backdrop {
background: rgb(0 0 0 / 50%);
backdrop-filter: blur(4px);
}::backdrop sits right under the modal in the top layer, so no extra overlay element or z-index is needed.
Common mistakes
::backdropdoesn't show because the dialog was opened withshow().- Adding a separate overlay
<div>that stays below the top layer anyway.
Key points
- The dialog opens with
showModal(), or the element is a shown popover, so it is in the top layer and gets::backdrop. - The backdrop isn't faked with a full-screen
<div>overlay. - Backdrop clicks are handled on the
<dialog>element, since::backdrophas no event listeners of its own.
Interview questions
Why is my ::backdrop not showing?
The element is not in the top layer. Open the dialog with showModal(), the popover with showPopover(), or the element with requestFullscreen().
Can I animate ::backdrop?
Yes. Transition its background-color or opacity and set the start values in @starting-style so it fades in on open.