Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / CSS

::backdrop — background behind a top-layer element

The ::backdrop pseudo-element styles the background beneath an element rendered in the top layer, for example to dim a page behind a modal dialog.

Version: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, per-example verification still required

Syntax

element::backdrop { background: rgb(0 0 0 / 50%); }

::backdrop is a fully styleable pseudo-element of an element rendered in the top layer. Its box is painted below its originating element but above ordinary page content.

Browser default rules should set position: fixed and inset: 0, covering the viewport. The selector #demo::backdrop restricts styling to the backdrop of #demo; the selector itself does not move an element into the top layer.

The example opens a modal using showModal(). Translucent black dims the page without changing the dialog's own color. Each top-layer element has its own ::backdrop.

Examples

<!doctype html>
<html lang="en">
<meta charset="utf-8">
<title>Backdrop example</title>
<style>
  body { background: white; }
  #demo { background: white; color: black; padding: 2rem; }
  #demo::backdrop { background: rgb(0 0 0 / 50%); }
</style>
<p>Page content behind the dialog.</p>
<dialog id="demo" aria-labelledby="heading">
  <h1 id="heading">Modal dialog</h1>
  <form method="dialog"><button>Close</button></form>
</dialog>
<script>
  document.getElementById('demo').showModal();
</script>
</html>

Result

On load, a white modal dialog appears over the page. A translucent black backdrop dims the surrounding white page to gray. Activating Close dismisses the dialog and removes its backdrop.

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources