CSS Reference ยท Pseudo-elements
The ::backdrop pseudo-element
Reference for the CSS ::backdrop pseudo-element: style the layer behind modal dialogs, popovers and fullscreen elements with colors, blur and transitions.
The ::backdrop pseudo-element is a box that fills the viewport directly behind an element that is shown in the browser's top layer: a modal <dialog> opened with showModal(), an element in fullscreen, or an open popover. Everything else on the page is below it.
By default a modal dialog has a faint dark backdrop and a popover has none. With ::backdrop you set the dimming color, add blur or run a fade.
dialog::backdrop { background: rgb(0 0 0 / 0.6); }
Try it
Syntax
dialog::backdrop { } [popover]::backdrop { } :fullscreen::backdrop { }
| Property | Value |
|---|---|
| Applies to | Elements in the top layer |
| Inherited | Not inherited from the page; see notes |
| Animatable | Its properties can transition (see notes) |
Values
The pseudo-element takes no arguments. Typical declarations:
| Property | Description |
|---|---|
background |
Dimming color or gradient. |
backdrop-filter |
Blur or other filter of what is behind. |
opacity, transition |
Fade the backdrop in and out. |
position, inset |
Fixed by the browser; changes are ignored. |
Usage notes
- Only top-layer elements. A normal element, or a dialog opened with
show()(non-modal), has no backdrop. - Clicks hit the dialog. The backdrop receives clicks outside the dialog. A common pattern closes the dialog when the click target is the
<dialog>element itself. - Custom properties don't reach it reliably. Do not depend on variables from
:rootbeing available inside::backdrop. Set values directly or declare the variable on::backdropitself. - Animating open and close. Use
@starting-styleandtransition-behavior: allow-discretefor entry and exit fades; it needs a recent browser. - Scroll. The page behind a modal dialog is made inert but can still scroll; set
overflow: hiddenon the body if you need to stop it. - Accessibility. Do not remove the dimming completely: it tells sighted users that the page behind is not active.
Browser support
Supported in all current browsers for modal dialogs, popovers and fullscreen. Animating the backdrop with @starting-style needs recent versions.
Related
:modal:open::details-content- Lesson: Pseudo-elements