Styling a dialog and its backdrop in CSS
The backdrop is a pseudo-element, and the dialog is in the top layer above everything.
dialog {
inset: 0;
margin: auto;
max-inline-size: min(32rem, 90vw);
padding: 1.5rem;
border: 0;
border-radius: 0.75rem;
box-shadow: 0 20px 60px rgb(15 23 42 / 0.25);
}
dialog::backdrop {
background: rgb(15 23 42 / 0.45);
backdrop-filter: blur(2px);
}
body:has(dialog[open]) { overflow: hidden; }
How it works
::backdropstyles the layer the browser paints behind a modal.- A closed dialog is
display: none, so animate it withallow-discrete. inset: 0plusmargin: autocenters a dialog of any size.
Keywords and builtins used here
backgroundblurborderinsetmarginminoverflowpaddingpxremrgbvw
The run, in numbers
- Lines
- 16
- Characters to type
- 297
- Tokens
- 91
- Three-star pace
- 85 tpm
At the three-star pace of 85 tokens a minute, this run takes about 64 seconds.
Step 3 of 4 in Surfaces, step 5 of 13 in Styling components.