CSS dialog styling: why open, :open, and :modal are not interchangeable
The HTML dialog element has two distinct open methods — show() for non-modal and showModal() for modal — and each exposes different CSS styling hooks. Developers can target an open dialog using the [open] attribute selector, the :open pseudo-class (now supported in Safari 26.5), or the :modal pseudo-class, which carries higher specificity and applies only to modal instances. Modal dialogs automatically gain a ::backdrop pseudo-element in the top layer, which can be styled with opacity transitions, blur effects, and @starting-style for smooth open animations. Focus management and page inertness are handled automatically for modal dialogs, but non-modal dialogs leave the rest of the page interactive, requiring overscroll-behavior: contain to prevent background scrolling. A key takeaway from the article is to reserve the dialog element for true modal use cases, and rely on the Popover API for most other overlay patterns.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in