Pretzel · 2026-11-22
CSS popover with no JavaScript
A CSS popover lets you open a floating panel, tooltip, or confirmation card on top of the page using plain HTML and CSS, with no JavaScript and no z-index math. The browser handles the stacking layer, the Escape key, and clicking outside for you.
Why load a modal library just to pop open a polite little box?
Try the HTML popover live
Both buttons below run on plain HTML attributes and CSS alone. Open one, test clicking the dimmed backdrop or pressing Esc, then compare how each mode behaves.
popover="auto"
Auto-dismiss popover
Best for menus, quick tips, and short confirmations. Clicking anywhere outside the box or pressing Esc closes it right away, and opening a second auto popover closes the first.
Light-dismiss + ::backdroppopover="manual"
Manual popover
Best for pinned notices or status cards the visitor should acknowledge on purpose. Outside clicks and Esc leave it alone until you press its close button or click the trigger again.
Explicit close only
popover="auto"
Zero-script auto popover
This panel sits in the browser's top layer above sticky headers and cards, with a dimmed ::backdrop behind it. Click outside, press Esc, or use the button below.
popover="manual"
Zero-script manual popover
Clicking the page behind this card will not close it, and pressing Esc will not dismiss it either. Use the button below to put it away.
What the Popover API handles for you
Before native popovers, every floating box needed click-outside listeners, keyboard traps, and ever-higher z-index guesses. Three built-in pieces replace all of that.
01
Top-layer placement
An open popover jumps straight to the browser's top layer. Overflow clipping on a parent card or a sticky header can never slice it in half.
02
Built-in ::backdrop
Style
::backdropright in CSS to dim or softly blur the page behind the open panel, with no extra wrapper div in your HTML.03
@starting-style entry
Because closed popovers switch from
display: none,@starting-styletells the browser where to begin the fade and gentle glide.
Copy the HTML popover and CSS
<!-- Auto-dismiss: outside click or Escape closes it -->
<button type="button" popovertarget="note-auto">Open auto popover</button>
<div id="note-auto" popover="auto" class="pop">
<h3>Quick stash note</h3>
<p>Click outside or press Escape to close this panel.</p>
<button type="button" popovertarget="note-auto" popovertargetaction="hide">Close</button>
</div>
<!-- Manual: stays open until its own button closes it -->
<button type="button" popovertarget="note-manual">Open manual popover</button>
<div id="note-manual" popover="manual" class="pop">
<h3>Pinned notice</h3>
<p>Outside clicks leave this one open until you dismiss it.</p>
<button type="button" popovertarget="note-manual" popovertargetaction="hide">Dismiss</button>
</div>.pop {
margin: auto;
max-width: min(26rem, calc(100vw - 2rem));
padding: 1.4rem 1.5rem;
border: 2px solid #86e3be;
border-radius: 16px;
background: #1e1033;
color: #fff2de;
box-shadow: 0 24px 60px rgb(0 0 0 / 0.65);
}
/* Dim the page behind the open popover */
.pop::backdrop {
background: rgb(14 6 25 / 0.72);
backdrop-filter: blur(4px);
}/* Smooth entry and exit with @starting-style (no JavaScript) */
@media (prefers-reduced-motion: no-preference) {
.pop {
opacity: 0;
transform: translateY(10px) scale(0.97);
transition:
opacity 0.22s ease,
transform 0.22s ease,
overlay 0.22s allow-discrete,
display 0.22s allow-discrete;
}
.pop:popover-open {
opacity: 1;
transform: translateY(0) scale(1);
}
@starting-style {
.pop:popover-open {
opacity: 0;
transform: translateY(10px) scale(0.97);
}
}
.pop::backdrop {
opacity: 0;
transition: opacity 0.22s ease, overlay 0.22s allow-discrete, display 0.22s allow-discrete;
}
.pop:popover-open::backdrop {
opacity: 1;
}
@starting-style {
.pop:popover-open::backdrop {
opacity: 0;
}
}
}Browser support: The HTML popover attribute and ::backdrop work across current Chrome, Edge, Safari, and Firefox. Smooth entry transitions with @starting-style and allow-discrete work in current Chrome, Edge, and Safari (and recent Firefox), while older versions still open and close the box cleanly without the fade. Tested in Chromium only.
The fine print, in plain words
Why this is free
We're raccoons who think simple things shouldn't cost a monthly fee. We take techniques apart, explain them in plain words, and give them away. The code on this page is MIT licensed: copy it, change it, and share it.
This is one of twelve experiments so far. Our first browser tool (Bandit Codes) is live now, and the rest sit as ideas in the stash.
Next snack
CSS text-wrap: balance vs pretty, live
Drag one width slider and watch headlines and paragraphs clean up their own line breaks.