Skip to content

Dialog Examples

The examples below assume that you have imported the component and set up the theme.

Basic

Open and close a dialog from a button. data-sv-dialog-toggle on a button toggles the dialog with that id, data-sv-dialog-close closes it, close-button adds a close button in the corner, and aria-labelledby names the dialog.

Welcome aboard

This is a modal dialog, so the rest of the page is blocked while it is open. Close it with the button below, the button in the corner, the Escape key, or a click on the backdrop, depending on what is turned on.

--opened
Close button
An SVG in the close-icon slot.
Dismiss
<div class="dialog-basic">
<button type="button" class="btn" data-sv-dialog-toggle="basic-dialog">Open dialog</button>
</div>
<sv-dialog id="basic-dialog" aria-labelledby="basic-dialog-title" close-button>
<h2 id="basic-dialog-title">Welcome aboard</h2>
<p>
This is a modal dialog, so the rest of the page is blocked while it is open. Close it with the
button below, the button in the corner, the Escape key, or a click on the backdrop, depending on
what is turned on.
</p>
<button type="button" class="btn btn-surface" data-sv-dialog-close="basic-dialog">Close</button>
</sv-dialog>
<style>
.dialog-basic {
display: flex;
align-items: center;
justify-content: center;
}
#basic-dialog h2 {
margin-block-start: 0;
}
#basic-dialog .btn {
display: block;
margin-inline-start: auto;
}
#basic-dialog svg[slot="close-icon"] {
display: block;
inline-size: auto;
block-size: 1.4rem;
fill: var(--sv-accent);
}
</style>

Non-Modal

Keep the page usable while the dialog is open. non-modal allows page interaction, --sv-dialog-backdrop-bg: transparent drops the dimming, and backdrop-dismiss closes the dialog on a click outside it.

The page stays usable

Try the counter button behind this dialog, it still works. Clicking anywhere outside the dialog dismisses it, and so does the Escape key.

<div class="dialog-non-modal">
<button type="button" class="btn" data-sv-dialog-toggle="non-modal-dialog">
Open non-modal dialog
</button>
<button id="page-counter" type="button" class="btn">Clicked 0 times</button>
</div>
<sv-dialog
id="non-modal-dialog"
aria-labelledby="non-modal-dialog-title"
backdrop-dismiss
close-button
non-modal
>
<h2 id="non-modal-dialog-title">The page stays usable</h2>
<p>
Try the counter button behind this dialog, it still works. Clicking anywhere outside the dialog
dismisses it, and so does the Escape key.
</p>
</sv-dialog>
<script type="application/x-typescript" module>
const counter = document.querySelector("#page-counter")!;
let clicks = 0;
counter.addEventListener("click", () => {
clicks += 1;
counter.textContent = `Clicked ${clicks} times`;
});
</script>
<style>
#non-modal-dialog {
--sv-dialog-backdrop-bg: transparent;
h2 {
margin-block-start: 0;
}
}
.dialog-non-modal {
display: flex;
flex-wrap: wrap;
gap: 0.75em;
justify-content: center;
}
</style>

Stacked

Open a dialog on top of another one. A data-sv-dialog-toggle button inside the first dialog opens the sv-dialog nested in it, and the stack shares one backdrop.

First dialog

Open a second dialog on top of this one.

Second dialog

Escape or a backdrop click closes only this dialog. The first one stays open below it.

--stacked
<div class="dialog-stacked">
<button type="button" class="btn" data-sv-dialog-toggle="stacked-first-dialog">
Open dialog
</button>
</div>
<sv-dialog
id="stacked-first-dialog"
aria-labelledby="stacked-first-dialog-title"
backdrop-dismiss
close-button
>
<h2 id="stacked-first-dialog-title">First dialog</h2>
<p>Open a second dialog on top of this one.</p>
<button type="button" class="btn btn-surface" data-sv-dialog-toggle="stacked-second-dialog">
Open second dialog
</button>
<sv-dialog
id="stacked-second-dialog"
aria-labelledby="stacked-second-dialog-title"
backdrop-dismiss
close-button
>
<h2 id="stacked-second-dialog-title">Second dialog</h2>
<p>Escape or a backdrop click closes only this dialog. The first one stays open below it.</p>
</sv-dialog>
</sv-dialog>
<style>
#stacked-first-dialog button[data-sv-dialog-toggle] {
border-color: var(--sv-gray-4);
}
.dialog-stacked {
display: flex;
justify-content: center;
}
#stacked-first-dialog h2,
#stacked-second-dialog h2 {
margin-block-start: 0;
}
</style>

Scrolling

Handle content taller than the dialog. The default slot content scrolls inside the dialog, and data-sv-dialog-close buttons in a footer at its end close the dialog.

Terms of Service

1. Acceptance of Terms

The services provided by staticview Components are subject to the following Terms of Use. We reserve the right to update these terms at any time without notice to you. The most current version can be reviewed by clicking on the "Terms of Use" hypertext link located at the bottom of our Web pages.

2. Privacy and Protection of Personal Information

See the Privacy Policy disclosures relating to the collection and use of your information. We prioritize data encryption and ensure that your personal identifiers are never shared with third-party advertisers without explicit consent.

3. User Conduct

As a condition of your use of the Services, you will not use the Services for any purpose that is unlawful or prohibited by these terms, conditions, and notices. You may not use the Services in any manner that could damage, disable, overburden, or impair any server, or the network(s) connected to any server.

4. Limitation of Liability

In no event shall staticview be liable for any special, indirect, or consequential damages or any damages whatsoever resulting from loss of use, data, or profits, whether in an action of contract, negligence, or other tortious action, arising out of or in connection with the use or performance of software or documents.

5. Termination of Use

We may terminate your access to all or any part of the Service at any time, with or without cause, with or without notice, effective immediately, which may result in the forfeiture and destruction of all information associated with your membership.

<div class="dialog-scrolling">
<button type="button" class="btn" data-sv-dialog-toggle="terms-dialog">
Read Terms of Service
</button>
</div>
<sv-dialog id="terms-dialog" aria-labelledby="terms-dialog-title" close-button>
<h2 id="terms-dialog-title">Terms of Service</h2>
<section>
<h3>1. Acceptance of Terms</h3>
<p>
The services provided by staticview Components are subject to the following Terms of Use. We
reserve the right to update these terms at any time without notice to you. The most current
version can be reviewed by clicking on the "Terms of Use" hypertext link located at the bottom
of our Web pages.
</p>
</section>
<section>
<h3>2. Privacy and Protection of Personal Information</h3>
<p>
See the Privacy Policy disclosures relating to the collection and use of your information. We
prioritize data encryption and ensure that your personal identifiers are never shared with
third-party advertisers without explicit consent.
</p>
</section>
<section>
<h3>3. User Conduct</h3>
<p>
As a condition of your use of the Services, you will not use the Services for any purpose that
is unlawful or prohibited by these terms, conditions, and notices. You may not use the
Services in any manner that could damage, disable, overburden, or impair any server, or the
network(s) connected to any server.
</p>
</section>
<section>
<h3>4. Limitation of Liability</h3>
<p>
In no event shall staticview be liable for any special, indirect, or consequential damages or
any damages whatsoever resulting from loss of use, data, or profits, whether in an action of
contract, negligence, or other tortious action, arising out of or in connection with the use
or performance of software or documents.
</p>
</section>
<section>
<h3>5. Termination of Use</h3>
<p>
We may terminate your access to all or any part of the Service at any time, with or without
cause, with or without notice, effective immediately, which may result in the forfeiture and
destruction of all information associated with your membership.
</p>
</section>
<div class="dialog-footer">
<button type="button" class="btn btn-surface" data-sv-dialog-close="terms-dialog">
Decline
</button>
<button type="button" class="btn btn-primary" data-sv-dialog-close="terms-dialog">
I Accept
</button>
</div>
</sv-dialog>
<style>
.dialog-scrolling {
display: flex;
justify-content: center;
}
#terms-dialog {
h2 {
padding-block-end: 0.5em;
margin-block-start: 0;
border-block-end: 1px solid var(--sv-gray-5);
}
section {
line-height: 1.6;
}
.dialog-footer {
display: flex;
gap: 0.75em;
justify-content: flex-end;
padding-block-start: 1em;
margin-block-start: 1.5em;
border-block-start: 1px solid var(--sv-gray-5);
}
}
</style>