Skip to content

Styling

Every rule ships inside @layer surface-elements. Any rule you write outside a layer wins, whatever its specificity, so you never need !important.

/* Beats the library's padding, no specificity games. */
surface-drawer > dialog {
padding: 2rem;
}

If you use layers yourself, declare the order once:

@layer reset, surface-elements, components;

Set them on the dialog, on <surface-drawer> or on any ancestor.

PropertyDefaultDescription
--surface-drawer-size28remInline size for start/end, block size for top/bottom (auto).
--surface-drawer-max-sizecalc(100% - 3rem)Upper bound for the size.
--surface-drawer-padding1remPadding of the dialog.
--surface-drawer-backgroundCanvasBackground of the dialog.
--surface-drawer-colorCanvasTextText color of the dialog.
--surface-drawer-bordernoneBorder of the dialog.
--surface-drawer-radius0Border radius of the dialog.
--surface-drawer-shadow0 0 2rem rgb(0 0 0 / 0.2)Shadow of the dialog.
--surface-drawer-backdroprgb(0 0 0 / 0.5)Backdrop background.
--surface-drawer-backdrop-filternoneBackdrop filter.
--surface-drawer-duration0.3sEnter and exit transition duration.
--surface-drawer-easingcubic-bezier(0.38, 0.005, 0.215, 1)Enter and exit easing.
Themed drawer

Rounded, blurred, slower

<surface-drawer edge="bottom">
<dialog
style="
--surface-drawer-radius: 1rem 1rem 0 0;
--surface-drawer-padding: 1.5rem;
--surface-drawer-backdrop: rgb(0 0 0 / 0.25);
--surface-drawer-backdrop-filter: blur(4px);
--surface-drawer-duration: 0.5s;
--surface-drawer-max-size: 60vh;
"
></dialog>
</surface-drawer>
Selector Matches
surface-drawer > dialog[open] An open drawer.
surface-drawer > dialog[data-closing] A drawer playing a fallback exit animation.
surface-drawer:state(open) The web component while its dialog is open.
/* Dim the trigger area while the cart is open. */
body:has(surface-drawer:state(open)) .toolbar {
opacity: 0.5;
}

The drawer slides in from its edge. Under prefers-reduced-motion: reduce it fades instead, and the duration drops to 0.15s.