The ::backdrop pseudo-element represents the surface immediately behind an element in the top layer. A modal dialog shown with showModal() receives a backdrop. Styling it does not turn a nonmodal dialog or a regular div into a modal interaction.
CSS ::backdrop: dim a modal without faking modality
When to use it
A review screen opens a confirmation dialog before a destructive case action. Give the modal a restrained opaque backdrop that separates the dialog from busy records, while keeping the dialog content readable. The sample targets only the intended dialog class. Verify the dialog is actually opened modally, traps interaction as the platform expects, has a clear title and close route, and returns focus to the invoking control when appropriate. Test the backdrop with another top-layer element, at high zoom, in forced colors, and with motion reduction. A dark overlay can conceal context but cannot explain the action: the dialog text must identify what will be changed. Avoid a transparent backdrop over sensitive-looking controls that encourages users to click through; underlying interaction behavior comes from the dialog API, not the color of the overlay. When the UI is nonmodal, do not make it look modal merely by painting a sheet.
.case-confirmation::backdrop { background-color: rgb(12 30 42 / 72%); }
@media (forced-colors: active) { .case-confirmation::backdrop { background-color: Canvas; } }Cost and verification
A solid or translucent color is cheap to paint compared with a full-screen blur. Backdrop filters can increase compositing work, especially during animation, and are unnecessary for this task. Measure text contrast on the dialog itself as well as the backdrop's separation from the page. Forced-color systems may override the color, so the dialog needs its own border and clear heading. A top-layer backdrop is separate from the dialog element; styling the page body will not replace it. CSS does not implement focus return, Escape handling, or a destructive-action guard; those belong to the platform and application flow.
Common Mistakes
- Do not expect ::backdrop to make an ordinary div modal.
- Do not hide the dialog's purpose behind a visual overlay.
- Do not rely on backdrop paint for focus management or dismissal.
Connected lessons
- CSS Property Decisions
- CSS backdrop-filter: preserve contrast beneath translucent panels
- CSS stacking contexts: debug overlays without arbitrary z-index inflation
- CSS dark mode and forced colors: honor distinct user settings
- HTML details and dialog: distinguish disclosure from a modal task
