CSS Tooltip Generator
- CSS anchor positioning, no library
- Flips when it runs out of room
- Hover, keyboard focus or click popover
- Browser support beside the code
Controls
Browser support
Support data last reviewed .
What CSS anchor positioning does
CSS anchor positioning attaches one element to another. The trigger gets an anchor-name, the tooltip refers to it with position-anchor, and position-area says which side to sit on. The browser keeps them together through scrolling and resizing, and position-try-fallbacks moves the tooltip to the other side when it would overflow, the job JavaScript libraries such as Popper and Floating UI used to do.
Syntax
anchor-name: --tooltip; position-anchor: --tooltip; position-area: top; position-try-fallbacks: flip-block;
| Part | What it controls |
|---|---|
| anchor-name | Goes on the trigger. A dashed name, written like a custom property, that other elements can attach to. |
| position-anchor | Goes on the tooltip, which must be absolutely or fixed positioned. Names the anchor it follows. |
| position-area | Which cell of an imaginary 3×3 grid around the anchor the tooltip fills: top, bottom, left, right, or spans such as top span-right. |
| position-try-fallbacks | Positions to try when the tooltip would overflow. flip-block swaps top and bottom; flip-inline swaps left and right. |
| anchor() | For finer control, places one edge against a named edge of the anchor, for example top: anchor(bottom). |
| popover | An HTML attribute that turns an element into a click-to-open layer in the top layer, with Esc and click-outside closing built in. |
| @starting-style | Defines where an entry transition starts, so a popover can fade in from display: none. |
Notes from practice
Tooltips need more than CSS
Point the trigger at the tooltip with aria-describedby so screen readers announce it, and show it on :focus-visible as well as :hover so keyboard users get it too. The generated hover CSS covers both states.
The arrow does not flip
position-try-fallbacks moves the tooltip, but its ::after arrow stays on the original side. If a tooltip may flip near the edge of the screen, drop the arrow or leave room on that side.
Popovers live in the top layer
A popover is never clipped by an overflow: hidden parent or buried by z-index, and it closes on Esc or an outside click. Anchor positioning then puts it next to its button instead of in the middle of the screen.
CSS Tooltip Generator FAQ
How do I make a tooltip with CSS only?
Give the trigger anchor-name: --tooltip, then give the tooltip position: absolute, position-anchor: --tooltip and position-area: top. Show it with :hover and :focus-visible on the trigger. No JavaScript is needed to position it.
Which browsers support CSS anchor positioning?
Chrome and Edge 125, Safari 26 and Firefox 147. Firefox 147 made it Baseline Newly available in January 2026. Older browsers ignore it, so keep the content readable without it.
How do I stop a tooltip going off screen?
Add position-try-fallbacks: flip-block, or flip-inline for tooltips on the left or right. When the tooltip would overflow, the browser tries the mirrored position instead.
What is the difference between a tooltip and a popover?
A tooltip appears on hover or focus and holds a short description. A popover opens on click, can hold interactive content, sits in the top layer and closes on Esc. The Show on control writes either.
Do I still need Popper or Floating UI?
For tooltips, menus and popovers in current browsers, mostly not: anchor positioning handles placement and flipping natively. A library still helps if you must support browsers from before 2026 or need collision handling beyond flipping.
Related generators
- Form Controls & Scrollbars — accent-color, caret-color, color-scheme, ::selection, ::placeholder, scrollbar styling and textarea behaviour.
- Transition — Tune duration, delay and easing, including cubic-bezier curves and spring or bounce easing with linear().
- CSS Carousel — A carousel with no JavaScript: scroll snap for the slides, plus native ::scroll-button() arrows and ::scroll-marker dots.
- Keyframe Animation — Pick a ready-made @keyframes set and tune timing, repeat, direction and fill mode.
More in UI & Interaction
Part of CSSGen.dev — 34 free visual CSS generators with browser support built in.