Modal
Any content as a modal, without the content knowing it is in one. The modal gives it the top layer, a locked page, Esc and focus returned. The content names and closes it with attributes — data-channel="title", "description", "close" — no id, any framework.
An alert
Closed only by an answer.
<ActionButton intent="destructive" command="show-modal" commandfor="delete">Delete everything</ActionButton>
<Modal id="delete" role="alertdialog" dismiss="none">
<Card padding="none" style="justify-self: center">
<div style="padding: var(--size-2xl) var(--site-offset)">
<Heading text="Delete everything?" data-channel="title" />
<ActionButton intent="destructive" data-channel="close" value="delete">Delete</ActionButton>
<ActionButton emphasis="secondary" data-channel="close" value="cancel">Cancel</ActionButton>
</div>
</Card>
</Modal>Long content
The modal scrolls, the page does not. A click beside the content closes it.
<ActionButton emphasis="secondary" command="show-modal" commandfor="terms-of-use">Read the terms</ActionButton>
<Modal id="terms-of-use" dismiss="any">
<Card padding="none" style="justify-self: center">
<div style="padding: var(--size-2xl) var(--site-offset)">
<Heading text="Terms" data-channel="title" />
{Array.from({ length: 20 }, (_, i) => <Text text={`Section ${i + 1}. Long enough to be taller than the window.`} />)}
<ActionButton data-channel="close" value="read">Done</ActionButton>
</div>
</Card>
</Modal>A drawer
The content places itself; the modal has no placement.
<ActionButton emphasis="secondary" command="show-modal" commandfor="filters">Filters</ActionButton>
<Modal id="filters" dismiss="any">
<Card padding="none" style="justify-self: end; align-self: stretch; inline-size: 24rem">
<div style="padding: var(--size-2xl) var(--site-offset)">
<Heading text="Filters" data-channel="title" />
<ActionButton emphasis="secondary" data-channel="close" value="done">Done</ActionButton>
</div>
</Card>
</Modal>A banner
Neither Esc nor a click beside it closes it — only a choice.
<ActionButton emphasis="secondary" command="show-modal" commandfor="consent">Show the banner</ActionButton>
<Modal id="consent" dismiss="none">
<Card padding="none" style="align-self: end">
<div style="padding: var(--size-2xl) var(--site-offset)">
<Heading text="Cookies" data-channel="title" />
<Text text="We remember your choices." data-channel="description" />
<ActionButton data-channel="close" value="accept">Accept</ActionButton>
<ActionButton emphasis="secondary" data-channel="close" value="reject">Reject</ActionButton>
</div>
</Card>
</Modal>Its name keeps the content's language
The modal owns no words; its name is the content's title, in the title's language.
<ActionButton emphasis="secondary" command="show-modal" commandfor="welcome">Open in Swedish</ActionButton>
<Modal id="welcome">
<Card padding="none" style="justify-self: center" lang="sv">
<div style="padding: var(--size-2xl) var(--site-offset)">
<Heading text="Välkommen tillbaka" data-channel="title" />
<ActionButton data-channel="close" value="ok">Stäng</ActionButton>
</div>
</Card>
</Modal>Every case, measured, is on the test bench.