DevTools Logo

CSS Anchor Positioning Lab

CSS Anchor Positioning Lab

Experiment with anchor(), position-area and position-try fallbacks, then copy the CSS.

Runs in your browser

Anchor positioning is browser-dependent. The generated CSS is gated behind @supports and degrades to a static popover where unsupported.

Try an example

Anchor controls

anchor
Anchor
Anchored popover

The stage is a schematic preview; exact placement depends on your browser's anchor-positioning support.

Generated CSS

valid

Examples

Tooltip

Input
inset bottom: anchor(top); fallbacks flip-block
Output
bottom: anchor(top, 0px);

The tooltip sits above the trigger and flips when clipped.

Dropdown

Input
position-area bottom span-right, anchor-size width
Output
width: anchor-size(width);

The menu starts at the anchor edge and shares its width.

Invalid name

Input
anchorName: trigger
Output
anchor-name must be a custom ident

Custom idents start with two dashes.

About this tool

CSS Anchor Positioning Lab turns the new anchor-positioning syntax into a set of visible controls. Place a popover with anchor() insets or the three-by-three position-area grid, add an ordered position-try-fallbacks chain, choose a try order and size the target with anchor-size(). Every change is reflected immediately in copy-ready CSS.

The output is gated behind @supports (anchor-name: --x) so unsupported browsers simply keep their existing layout. Validation checks that anchor names are valid custom idents, flags duplicate or unusual fallback entries and explains when a value may need a browser-support check.

Presets cover the common patterns: a tooltip that flips, a dropdown that spans right and matches the trigger width, a select-like popover and a cursor badge. The schematic stage shows the relationship between the anchor and the anchored element; final placement is always the browser's decision.

What this tool does not do

  • Browser support is partial; the generated CSS is gated behind @supports.
  • The stage is schematic and does not reproduce browser overflow resolution.
  • Custom @position-try blocks are not authored; use custom try names only.
  • No shadow-DOM-specific cases are modeled.

How to use this tool

  1. Choose a placement strategy

    Use anchor() insets for explicit offsets or position-area for the keyword grid.

  2. Configure the anchor

    Enter a custom ident such as --trigger and set a margin around the anchored element.

  3. Build fallbacks

    List flip keywords, area keywords or custom --try names in the order the browser should try them.

  4. Copy the CSS

    Take the @supports-gated block into your stylesheet and optionally add the invoker markup.

Use cases

Design systems

Prototype tooltips and menus without JavaScript position calculations.

Teaching new CSS

Show how each declaration changes placement in one place.

Fallback planning

Check a flip chain before committing it to production styles.

Generated declarations

PropertyExample
anchor-name--trigger
position-areabottom span-right
insetanchor(bottom, 0px)
position-try-fallbacksflip-block, top center
anchor-size()width
position-visibilityanchors-visible

The CSS block is wrapped in @supports by default.

Common mistakes

Mistake:Using a plain ident for anchor-name.

Fix:Anchor names are custom idents such as --trigger.

Mistake:Forgetting a fallback inside anchor().

Fix:Provide a length like 0px so the position remains defined when anchoring fails.

Mistake:Assuming support everywhere.

Fix:Keep the @supports gate and a static fallback layout.

Mistake:Expecting exact positioning in the schematic stage.

Fix:The stage illustrates relationships; browsers decide final placement.

Frequently asked questions

Which browsers support anchor positioning?

Support is rolling out, with Chromium leading and other engines catching up. That is why the generated CSS is wrapped in @supports: unsupported browsers keep your existing layout instead of rendering a broken position.

How do fallbacks pick their order?

The browser walks position-try-fallbacks from first to last and picks the first position that fits the viewport. position-try-order can prefer the option with the most height, most width or least overlap.

Can I anchor a popover without JavaScript?

Yes. anchor-name on the trigger plus position-area or anchor() insets on the popover is pure CSS, and the popover attribute supplies show/hide behavior. The lab can include the invoker markup in its output.

What is position-area versus anchor()?

position-area places the target in a nine-cell grid around the anchor using keywords. anchor() computes a specific inset from an anchor edge and accepts a fallback length. Both are valid; area placement is often shorter.

Does it work inside shadow DOM?

Anchoring is scoped by tree boundaries, so cross-root anchoring needs special handling. This lab models the ordinary same-tree case and does not generate shadow-DOM-specific rules.

Is my CSS uploaded?

No. Every control, preview and CSS emission runs locally in your browser tab.

References & standards