CSS Anchor Positioning Generator
Build tooltip, popover, and dropdown placements with anchor-name, position-anchor, position-area, and anchor() — preview live and copy production-ready CSS.
About This Tool
CSS Anchor Positioning is the first native, declarative way to attach one element to another in modern browsers. Before it shipped, every tooltip, dropdown, popover, and dialog needed a JavaScript library — Floating UI, Popper.js, Tippy — to measure the trigger, watch resize and scroll events, and re-position the floating element on every frame. With anchor-name, position-anchor, the anchor() function, and the position-area shorthand, the browser's layout engine does that work for you, with zero JavaScript.
This generator gives you a sandbox for the entire feature set. Drag the anchor around the preview area and watch the target follow in real time. Pick a placement from the 9-direction position-area grid (top, top-end, right, bottom-start, etc.) or switch to the explicit anchor() function for fine-grained per-axis control. Toggle the position-try-fallbacks panel to add overflow-recovery placements like flip-block and flip-inline, which let the browser auto-flip the target when it would overflow the viewport. The generated CSS panel emits a copy-ready snippet for both the anchor element and the target.
Browser support is the catch. Chrome and Edge shipped full anchor positioning in version 125 (May 2024). Safari 26 supports the core primitives but not the position-area shorthand. Firefox has not yet shipped the feature as of April 2026, so production code needs a fallback strategy: a JavaScript polyfill (Oddbird's CSS anchor positioning polyfill is the de facto choice), @supports rules with position: absolute defaults, or progressive enhancement that degrades to a static placement. The browser-support banner at the top of this page uses CSS.supports('anchor-name', '--x') to detect the current environment and switches the preview to a manual position fallback when needed.
If you're styling component-driven layouts, pair this generator with our Container Query Builder to scope anchor placements per container size, the CSS text-wrap Playground to compare wrap behavior inside narrow popovers, and the CSS Selector Reference when you need to target the trigger element from descendant selectors. The Viewport Size Reference is useful for choosing fallback positions that survive small mobile viewports.
Every input, drag, and generated CSS string stays inside this browser tab. Nothing is sent to a server, no analytics are tied to the strings you type, and the page works offline once loaded.
How to Use
- Pick an anchor name in the Identifiers card. It must start with
--(it's a CSS custom property scoped to anchor positioning). The default--anchor-1is fine for one-off snippets; use semantic names like--menu-triggeror--tooltip-sourcein production code. - The position-anchor field on the target mirrors the anchor name automatically. You only need to change it if the target should follow a different anchor (advanced — most apps use one anchor per target).
- Choose a placement with the 9-direction
position-areagrid (top, top-end, right, bottom-start, etc.). The preview updates live so you can see exactly how the target sits relative to the anchor. - Toggle "Use anchor() instead" to switch from the
position-areashorthand to the explicitanchor()function. This unlocks per-axis control: pin the target'stopto the anchor'sbottom, the target'sleftto the anchor'sright, and so on. - Adjust the Offset slider to add a small gap between anchor and target (typical values: 4–12px for tooltips, 0–4px for dropdowns, 8–16px for popovers).
- Drag the anchor in the preview to test edge cases (corners, edges, overlapping the viewport). For viewport-edge testing, enable position-try-fallbacks and add
flip-blockso the target auto-flips when it would overflow. - Click Copy CSS (or press
Ctrl+Shift+C) to copy the full generated stylesheet — both.anchorand.targetrules — to your clipboard.
Popular Examples
- Tooltip Anchored to a Button
- Dropdown Menu Anchored to a Trigger Button
- Popover with Anchor Positioning
- Modal Dialog Anchored to a Trigger Element
- Notification Badge Anchored to an Avatar
- Right-Click Context Menu with Anchor Positioning
- Autocomplete Suggestions Anchored to an Input
- Animated Tab Indicator with anchor-name
FAQ
What is CSS Anchor Positioning?
CSS Anchor Positioning is a 2024 CSS feature that lets one element (the target) be positioned relative to another element (the anchor) using pure CSS. The anchor declares an identifier with anchor-name: --x, the target opts in with position-anchor: --x, and then either the position-area shorthand (e.g. position-area: top) or the explicit anchor() function (e.g. top: anchor(--x bottom)) places the target. The browser handles all the math — including scroll, resize, and reflow — without any JavaScript. It replaces the popular Floating UI / Popper.js / Tippy libraries for tooltips, dropdowns, popovers, and dialogs.
When will Firefox support CSS Anchor Positioning?
As of April 2026 Firefox has not yet shipped CSS Anchor Positioning. The feature is tracked in Bugzilla (bug 1838746) and is on the roadmap, but no concrete ship date is committed. For Firefox-friendly production code, use Oddbird's CSS Anchor Positioning Polyfill (a small JavaScript shim that backfills the syntax in unsupported browsers), or wrap your anchor styles in @supports (anchor-name: --x) { ... } and provide an explicit position: absolute fallback for browsers without support. The 'browser-fallback-strategy' example on this page walks through both approaches.
What is the difference between anchor-name and position-anchor?
anchor-name is set on the anchor element — it declares 'I am an anchor; here is my identifier'. position-anchor is set on the target element — it says 'I want to follow the anchor identified by this name'. They must use the same custom-property identifier (both starting with --) for the connection to work. Think of anchor-name as a label you stick on the anchor, and position-anchor as the address the target ships to. In simple cases both have the same value; in advanced cases (multiple targets sharing one anchor, or one target switching anchors via JavaScript), they decouple.
Can I use anchor positioning with position: fixed?
Yes. Anchor positioning works with both position: absolute and position: fixed. The semantic difference is the same as ever: absolute positions the target relative to its containing block (the nearest positioned ancestor), while fixed positions it relative to the viewport. Both will follow the anchor's resolved position as the page scrolls or reflows. position: fixed is the right choice for tooltips and popovers that should escape an overflow: hidden ancestor (the classic 'tooltip clipped by a card boundary' problem). The toggle in this generator lets you switch between absolute and fixed and copy the corresponding CSS.
What does position-try-fallbacks do, and when should I use it?
position-try-fallbacks is a list of alternate placements the browser tries (in order) when the target would overflow its containing block. The most common values are flip-block (try the opposite block-axis side, e.g. swap top → bottom), flip-inline (swap left → right), or 'flip-block flip-inline' (swap both). You can also list specific position-area values like 'top, bottom, right, left' to give the browser a priority order. Use it whenever the target could overflow the viewport — almost always for tooltips and popovers that anchor near edges. It is the native equivalent of Floating UI's flip middleware.
How does this work with the HTML Popover API?
CSS Anchor Positioning was designed to pair with the HTML Popover API ([popover] attribute, popovertarget, etc.). The popover element is the target, and the trigger button is the anchor. Set anchor-name on the button, position-anchor on the popover, and the popover automatically follows its trigger — no JavaScript needed for placement. Browsers that support both features (Chrome 125+, Edge 125+, Safari 26+) get a fully declarative tooltip/menu/dialog stack. See the 'anchor-with-popover-api' example on this page for a complete pattern.
Is my data safe?
Yes. This generator runs entirely in your browser. The anchor and target identifiers, position-area values, fallback lists, and generated CSS are computed and rendered with React state and CSS — nothing is sent to a server. The browser-support banner uses the local CSS.supports() API, not a remote feature-detection service. There is no analytics tied to the values you enter, and the page works offline once loaded, so you can prototype proprietary component-library APIs (anchor names like '--my-app-tooltip') without any data leaving your machine.
Related Tools
CSS Container Query Builder
Build CSS container queries visually with container type, name, and size conditions.
CSS text-wrap Playground
Compare text-wrap: balance, pretty, wrap, and nowrap side-by-side with live font-size and container-width controls.
CSS color-mix Generator
Generate CSS color-mix() expressions in OKLCH, sRGB, Lab, HSL, and Display-P3. Live preview, ratio slider, and side-by-side color space comparison.
CSS Selector Reference
Complete interactive CSS selector reference with specificity calculator, live preview, searchable categories, and browser support for every selector.
Viewport Size Reference
Browse 60+ device viewport sizes for responsive web design. Compare iPhone, iPad, Android, laptop, desktop, and TV screen dimensions.