CSS Popover Toggletip

A click-to-open info bubble using the native popover attribute, placed above its button with CSS anchor positioning.

  • popover
  • toggletip
  • click tooltip
  • anchor positioning
  • popovertarget
  • no javascript
HTML
<button class="toggletip-btn" type="button" popovertarget="toggletip-1" aria-label="More info">?</button>
<div class="toggletip" id="toggletip-1" popover>
  Free shipping on orders over $50. Returns are free within 30 days.
</div>
CSS
.toggletip-btn {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 50%;
  background: #0891b2;
  color: #fff;
  font: 700 16px system-ui, sans-serif;
  cursor: pointer;
  anchor-name: --toggletip;
}

.toggletip-btn:focus-visible {
  outline: 2px solid #0891b2;
  outline-offset: 3px;
}

.toggletip {
  width: 220px;
  padding: 12px 14px;
  border: 0;
  border-radius: 12px;
  background: #164e63;
  box-shadow: 0 12px 28px -10px rgba(8, 51, 68, 0.5);
  color: #ecfeff;
  font: 14px/1.45 system-ui, sans-serif;
}

@supports (position-area: top) {
  .toggletip {
    position-anchor: --toggletip;
    position-area: top;
    position-try-fallbacks: flip-block;
    margin: 0 0 10px;
  }
}

About this CSS Popover Toggletip

This CSS Popover Toggletip is 38 lines of pure CSS (0.7 KB) with no JavaScript and no dependencies. It uses anchor positioning, box shadows, CSS Grid and keyboard focus styles. It relies on anchor positioning, which not every browser supports yet, so check the browser notes below. It works in any stack: plain HTML, React, Vue, Svelte, Astro, WordPress or Webflow.

CSS features used

Customize it

The colors in this snippet. Search and replace them to match your brand:

  • #0891b2
  • #fff
  • #164e63
  • #ecfeff

How to use this popover toggletip

  1. Copy the HTML and paste it where you want the element to appear.
  2. Copy the CSS into your stylesheet, or inside a <style> tag.
  3. Keep the .toggletip-btn class name, or rename it in both places. Then tweak colors, sizes and timing to match your design.
  4. Using React or Next.js? Change class to className in the HTML. The CSS works as is, including in Tailwind projects (put it in your global stylesheet).

Building with an AI tool?

“Copy for AI” copies a short prompt for Cursor, Claude Code, Lovable, Bolt or v0. Your AI tool opens the Markdown version of this snippet and reads the HTML, CSS and setup notes there. If your tool can't open links, with the code instead. More ways to use copy CSS with AI.

Feedback