Sandbox mode banner in HTML, CSS and vanilla JS
A copy-paste Sandbox mode banner in plain HTML and CSS, with vanilla JavaScript: no framework, no build step, MIT-licensed.
Live preview
Source (copy-ready)
<section class="dcl-banner-sandbox-mode" data-dcl-scheme="light" aria-label="Sandbox mode banner example">
<div data-row data-spread>
<div><span data-chip>Sandbox</span><h2>You're working with sample data</h2><p>No actions affect the live account.</p></div>
<label data-choice><input type="checkbox" aria-controls="dcl-banner-sandbox-mode-data">Show sample data source</label>
<p id="dcl-banner-sandbox-mode-data" data-well hidden>Sample records are bundled with this preview.</p>
</div>
<script>
(() => {
const root = document.currentScript.closest(".dcl-banner-sandbox-mode");
const instance = Array.from(document.getElementsByClassName("dcl-banner-sandbox-mode")).indexOf(root);
if (instance > 0) {
const ids = new Map();
for (const element of root.querySelectorAll("[id]")) {
ids.set(element.id, element.id + "--" + instance);
element.id = ids.get(element.id);
}
for (const element of root.querySelectorAll("[aria-labelledby], [aria-describedby], [aria-controls], [for], [href]")) {
for (const attribute of ["aria-labelledby", "aria-describedby", "aria-controls", "for"]) {
if (!element.hasAttribute(attribute)) continue;
const updated = element.getAttribute(attribute).split(/\s+/).map((id) => ids.get(id) || id);
element.setAttribute(attribute, updated.join(" "));
}
const href = element.getAttribute("href");
if (href && href.startsWith("#") && ids.has(href.slice(1))) element.setAttribute("href", "#" + ids.get(href.slice(1)));
}
}
const preference = matchMedia("(prefers-color-scheme: dark)");
const setTheme = () => { root.dataset.dclScheme = preference.matches ? "dark" : "light"; };
preference.addEventListener("change", setTheme);
setTheme();
const find = (selector) => root.querySelector(selector);
find("input").addEventListener("change", (event) => {
find("[data-well]").hidden = !event.target.checked;
});
})();
</script>
</section>
<style>
.dcl-banner-sandbox-mode, .dcl-banner-sandbox-mode * { box-sizing: border-box; }
.dcl-banner-sandbox-mode { font: 1rem/1.5 system-ui, sans-serif; max-inline-size: 40rem; padding: clamp(0.75rem, 3vw, 1.25rem); border: 1px solid; border-radius: 0.75rem; overflow-wrap: anywhere; }
.dcl-banner-sandbox-mode :where(h2, h3, p, ol, ul, dl, dd) { margin: 0; }
.dcl-banner-sandbox-mode h2 { font-size: 1.25rem; line-height: 1.25; }
.dcl-banner-sandbox-mode h3 { font-size: 1rem; }
.dcl-banner-sandbox-mode p + p { margin-block-start: 0.5rem; }
.dcl-banner-sandbox-mode [data-stack], .dcl-banner-sandbox-mode form { display: grid; gap: 0.75rem; }
.dcl-banner-sandbox-mode [data-row] { display: flex; flex-wrap: wrap; gap: 0.5rem 0.75rem; align-items: center; }
.dcl-banner-sandbox-mode [data-split] { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 14rem), 1fr)); gap: 0.75rem 1.25rem; align-items: start; }
.dcl-banner-sandbox-mode [data-spread] { justify-content: space-between; }
.dcl-banner-sandbox-mode [hidden] { display: none !important; }
.dcl-banner-sandbox-mode [data-well] { padding: 0.75rem; border-radius: 0.375rem; }
.dcl-banner-sandbox-mode [data-chip] { display: inline-block; width: fit-content; padding: 0.125rem 0.55rem; border-radius: 99rem; font-size: 0.875rem; font-weight: 700; }
.dcl-banner-sandbox-mode :where(button, summary, input, select) { font: inherit; }
.dcl-banner-sandbox-mode :where(button, input, select) { min-block-size: 44px; min-inline-size: 0; max-inline-size: 100%; }
.dcl-banner-sandbox-mode :where(button, input, select) { border: 1px solid; border-radius: 0.375rem; padding: 0.45rem 0.7rem; }
.dcl-banner-sandbox-mode :where(button, summary) { cursor: pointer; font-weight: 650; }
.dcl-banner-sandbox-mode :where(button, summary):active { box-shadow: inset 0 0 0 2px currentColor; }
.dcl-banner-sandbox-mode summary:hover { text-decoration: underline; }
.dcl-banner-sandbox-mode :where(button, input, select):disabled, .dcl-banner-sandbox-mode [aria-disabled=true] { cursor: not-allowed; border-style: dashed; }
.dcl-banner-sandbox-mode label { display: grid; gap: 0.25rem; }
.dcl-banner-sandbox-mode :where(input, select) { inline-size: 100%; }
.dcl-banner-sandbox-mode label[data-choice] { display: flex; gap: 0.5rem; align-items: center; min-block-size: 44px; }
.dcl-banner-sandbox-mode label[data-choice] input { inline-size: 1.25rem; block-size: 1.25rem; min-block-size: 0; flex-shrink: 0; }
.dcl-banner-sandbox-mode fieldset { min-inline-size: 0; margin: 0; border-radius: 0.375rem; padding: 0.5rem 0.75rem; }
.dcl-banner-sandbox-mode :focus-visible { outline: 3px solid #005c62; outline-offset: 2px; }
.dcl-banner-sandbox-mode[data-dcl-scheme="dark"] :focus-visible { outline: 3px solid #8fe1da; outline-offset: 2px; }
.dcl-banner-sandbox-mode { color-scheme: light; border-color: #697f84; }
.dcl-banner-sandbox-mode { color: #11292f; background-color: #ffffff; }
.dcl-banner-sandbox-mode [data-well], .dcl-banner-sandbox-mode [data-chip] { color: #11292f; background-color: #e4edef; }
.dcl-banner-sandbox-mode button, .dcl-banner-sandbox-mode input, .dcl-banner-sandbox-mode select { color: #11292f; background-color: #e4edef; }
.dcl-banner-sandbox-mode button[data-primary] { color: #ffffff; background-color: #00535a; }
.dcl-banner-sandbox-mode button:hover { color: #ffffff; background-color: #003c42; }
.dcl-banner-sandbox-mode button[disabled], .dcl-banner-sandbox-mode button[aria-disabled=true] { color: #405a60; background-color: #e4edef; }
.dcl-banner-sandbox-mode[data-dcl-scheme="dark"] { color-scheme: dark; border-color: #839fa5; }
.dcl-banner-sandbox-mode[data-dcl-scheme="dark"] { color: #eff8f9; background-color: #142f36; }
.dcl-banner-sandbox-mode[data-dcl-scheme="dark"] [data-well], .dcl-banner-sandbox-mode[data-dcl-scheme="dark"] [data-chip] { color: #eff8f9; background-color: #1c3c44; }
.dcl-banner-sandbox-mode[data-dcl-scheme="dark"] button, .dcl-banner-sandbox-mode[data-dcl-scheme="dark"] input, .dcl-banner-sandbox-mode[data-dcl-scheme="dark"] select { color: #eff8f9; background-color: #1c3c44; }
.dcl-banner-sandbox-mode[data-dcl-scheme="dark"] button[data-primary] { color: #11292f; background-color: #8fe1da; }
.dcl-banner-sandbox-mode[data-dcl-scheme="dark"] button:hover { color: #11292f; background-color: #b2f2ec; }
.dcl-banner-sandbox-mode[data-dcl-scheme="dark"] button[disabled], .dcl-banner-sandbox-mode[data-dcl-scheme="dark"] button[aria-disabled=true] { color: #b0c9ce; background-color: #1c3c44; }
</style>
When to use
Make it clear that a suite is using demo data while protecting the user's place in the workflow.
Avoid
Do not provide a fake exit-to-production action; environment switches should be explicit and verified.
Accessibility
The context is stated plainly rather than encoded in a color. The checkbox reveals sample-data details, not an environment switch. Text contrast is at least 6.1:1 in light and 6.7:1 in dark.
Was this useful? Send feedback.