CSS pseudo-elementPseudo-elements

::backdrop

Styles the background layer behind a modal dialog, a fullscreen element, and an open popover.

On this page

Example

#
CSS
.modal::backdrop {
  background: rgb(12 12 16 / 0.6);
  backdrop-filter: blur(3px);
}

.modal {
  padding: 18px 20px;
  border: 1px solid #3f3f46;
  border-radius: 14px;
  background: #18181b;
  color: inherit;
}
Preview

Click “Finish lesson” to open the dialog. Close it with a button in the dialog or the Esc key.

Definition and usage

#

The ::backdrop pseudo-element is a fullscreen layer that the browser places right beneath an element shown in the top layer. It appears under a <dialog> opened with the showModal() method, under an element in fullscreen mode, and under an open popover.

With it you can darken or blur the page behind the window without adding any overlay to the HTML. Under a dialog the backdrop is slightly darkened by default; you usually give it your own translucent colour, and sometimes backdrop-filter: blur() too.

A dialog opened with show() or the open attribute is not modal and has no backdrop. ::backdrop exists only for a dialog opened with showModal(), which blocks the rest of the page and closes with the Esc key.

Syntax

#
Syntax
selector::backdrop { property: value; }

Common styles

#
  • rgb(0 0 0 / 0.7)

    Strong darkening of the page behind the dialog. Click “Open dialog” and close it with the button or the Esc key.
  • rgb(124 58 237 / 0.45)

    A translucent filter in the brand colour instead of grey.
  • blur(4px)

    Blurs the page behind the dialog through backdrop-filter. The background content stays visible but doesn’t distract.
  • linear-gradient()

    A gradient instead of a solid colour, for example in the brand colours.

Common styles in practice

#

rgb(0 0 0 / 0.7)

Strong darkening of the page behind the dialog. Click “Open dialog” and close it with the button or the Esc key.
.demo::backdrop { background: rgb(0 0 0 / 0.7); }

rgb(124 58 237 / 0.45)

A translucent filter in the brand colour instead of grey.
.demo::backdrop { background: rgb(124 58 237 / 0.45); }

blur(4px)

Blurs the page behind the dialog through backdrop-filter. The background content stays visible but doesn’t distract.
.demo::backdrop {
  background: rgb(0 0 0 / 0.25);
  backdrop-filter: blur(4px);
}

linear-gradient()

A gradient instead of a solid colour, for example in the brand colours.
.demo::backdrop {
  background: linear-gradient(#7c3aed99, #0ea5e999);
}

Browser support

#

Widely available

Works in all modern browsers, phones included. You can use it without worry.

  • Chrome
  • Edge
  • Firefox
  • Safari

Good practices

#
  • Open a dialog that should be modal with showModal(), not with the open attribute. Only then does it get a ::backdrop, block the rest of the page, and close with the Esc key.
  • Clicking the backdrop does not close the dialog by itself. If you need that, add handling in JavaScript.
  • You can fade the backdrop in with an @keyframes animation applied to ::backdrop, for example from full transparency to the darkened state.

Related entries

#

Spotted a mistake or missing an example? Write to us.