Anchor-Positioned Popover
A copy-paste css-only interactions component in pure HTML & CSS. Zero dependencies, framework-agnostic, MIT-licensed.
CSS-Only InteractionsHTMLCSSany framework
Copy into your project
HTML
<!-- Anchor-Positioned Popover — the native Popover API (popover /
popovertarget) plus CSS anchor positioning (anchor-name /
position-anchor) place and toggle the panel. Esc and outside-click
close it automatically. Zero JS. -->
<div class="nuda-co2-anchor-popover">
<button class="nuda-co2-anchor-popover__trigger" type="button"
popovertarget="co2-ap-tip" popovertargetaction="toggle">
Show info
</button>
<div class="nuda-co2-anchor-popover__tip" id="co2-ap-tip" popover="auto">
Positioned automatically next to its trigger using native CSS anchor positioning — zero JS.
</div>
</div>CSS
.nuda-co2-anchor-popover {
--nuda-co2-ap-accent: #e4ff54;
position: relative;
display: inline-flex;
font-family: inherit;
}
.nuda-co2-anchor-popover__trigger {
anchor-name: --nuda-co2-ap-anchor;
display: inline-flex;
align-items: center;
justify-content: center;
min-height: 44px;
padding: .5rem 1.1rem;
font-size: .78rem;
font-weight: 600;
color: #fff;
background: rgba(255,255,255,.06);
border: 1px solid rgba(255,255,255,.14);
border-radius: 8px;
cursor: pointer;
transition: background .2s ease;
}
.nuda-co2-anchor-popover__trigger:hover {
background: rgba(255,255,255,.1);
}
.nuda-co2-anchor-popover__trigger:focus-visible {
outline: 2px solid var(--nuda-co2-ap-accent);
outline-offset: 2px;
}
.nuda-co2-anchor-popover__tip {
position: fixed;
position-anchor: --nuda-co2-ap-anchor;
position-area: top;
inset-area: top;
margin: 0 0 10px;
max-width: 200px;
padding: .6rem .75rem;
font-size: .72rem;
line-height: 1.45;
color: #09090b;
background: var(--nuda-co2-ap-accent);
border: none;
border-radius: 9px;
box-shadow: 0 16px 36px rgba(0,0,0,.45);
}
.nuda-co2-anchor-popover__tip:popover-open {
animation: _nuda-co2anchorpopoverpop .18s ease-out;
}
@keyframes _nuda-co2anchorpopoverpop {
from {
opacity: 0;
transform: translateY(4px) scale(.96);
}
to {
opacity: 1;
transform: translateY(0) scale(1);
}
}
@media (prefers-reduced-motion:reduce) {
.nuda-co2-anchor-popover__trigger {
transition: none;
}
.nuda-co2-anchor-popover__tip:popover-open {
animation: none;
}
}
How to use Anchor-Positioned Popover
Paste the HTML where you need it and the CSS into a global stylesheet (or a <style> tag). Every class is prefixed nuda- so it never collides with Tailwind or your own styles. Tweak the CSS custom properties to match your design system.
Works in React, Vue, Svelte, Astro, Next.js, Nuxt, Laravel Blade, Django, Rails — or a single .html file. No npm install, no build step.