::backdrop
Styles the background layer behind a modal dialog, a fullscreen element, and an open popover.
Example
#.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;
}<style>
.open, .modal button { padding: 8px 14px; border: 0; border-radius: 8px; background: #7c3aed; color: #fff; font: inherit; cursor: pointer; }
.modal button.ghost { background: #3f3f46; }
</style>
<div style="min-height: 190px;">
<div style="display: flex; gap: 6px; margin-bottom: 12px;"><div class="box">HTML</div><div class="box">CSS</div><div class="box">JS</div></div>
<button class="open" type="button" onclick="this.nextElementSibling.showModal()">Finish lesson</button>
<dialog class="modal">
<p style="margin: 0 0 12px;">Are you sure you want to finish the lesson?</p>
<form method="dialog" style="display: flex; gap: 8px;">
<button class="ghost">Go back</button>
<button>Finish</button>
</form>
</dialog>
</div>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
#selector::backdrop { property: value; }Common styles
#- Strong darkening of the page behind the dialog. Click “Open dialog” and close it with the button or the Esc key.
- A translucent filter in the brand colour instead of grey.
- Blurs the page behind the dialog through
backdrop-filter. The background content stays visible but doesn’t distract. - A gradient instead of a solid colour, for example in the brand colours.
Common styles in practice
#rgb(0 0 0 / 0.7)
.demo::backdrop { background: rgb(0 0 0 / 0.7); }rgb(124 58 237 / 0.45)
.demo::backdrop { background: rgb(124 58 237 / 0.45); }blur(4px)
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()
.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 theopenattribute. 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
@keyframesanimation applied to::backdrop, for example from full transparency to the darkened state.
Related entries
#- backdrop-filterApplies a filter to what is visible behind an element, for example blurring the background behind a panel.
- opacitySets the transparency of the whole element together with its contents.
- background-colorSets the background colour of an element.
- z-indexDetermines which element sits on top when elements overlap.
- @keyframesDefines the stages of an animation, known as keyframes.
Spotted a mistake or missing an example? Write to us.