::backdrop

Term side of the Card.
Topic: Pseudo Elements
Unit title: ::backdrop
Categories: Pseudo-element
Explanation side of the Card

Explanation: The pseudo-element that represents the backdrop behind a modal or fullscreen element. It allows styling the background that appears behind the content, often used to create dimming or blurring effects.

Browser compatibility:
  • The chrome browser supports this feature starting from version 37.
  • The edge browser supports this feature starting from version 79.
  • The firefox browser supports this feature starting from version 47.
  • The safari browser supports this feature starting from version 15.4.
Availability: 

Example

Wrongcss
.overlay {
  position: fixed;
  inset: 0;
  background: rgb(0 0 0 / 50%);
}
Rightcss
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

  • ::backdrop doesn't show because the dialog was opened with show().
  • 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 ::backdrop has 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.

Analytics cookiesWe'd like to use analytics cookies to see which pages are useful. They're set only if you accept. Privacy Policy