Skip to content

Menu

CSS Anchor Positioning Generator

Generate CSS anchor positioning code: anchor-name, position-anchor, position-area and position-try-fallbacks, with a live preview where supported.

Runs entirely in your browserFrontendFree, no sign-up
Loading tool

01What is CSS Anchor Positioning Generator?

Tooltips, dropdowns and popovers usually need a JavaScript library to measure a button and place a box beside it. CSS anchor positioning does this in the stylesheet. CSS Anchor Positioning Generator writes those rules for you, so you can tie a floating element to its trigger without JavaScript. You name the anchor, pick where the floating element should sit, and the tool outputs two rules. The first sets anchor-name on the trigger. The second gives the floating element position: absolute, position-anchor pointing at that name, and a position-area value. The CSS Anchor Positioning Module Level 1 draft from the CSS Working Group defines these properties. It says anchor-name takes a dashed ident, so the tool checks that your name looks like --trigger and shows an error otherwise. Pick the area with the two dropdowns or by clicking a cell in a 5 by 5 grid, where the shaded middle cell is the anchor. The spec describes position-area as a grid of rows and columns around the anchor box. The grid includes the span keywords, such as bottom span-right, which lines a menu up with the anchor's middle and lets it extend to the right. Choosing center in both directions outputs the single keyword center. A gap slider adds a margin on the side facing the anchor. A top placement gets margin-bottom, a left placement gets margin-right, and so on. It is skipped for center and span positions, because no single side faces the anchor there. You can add position-try-fallbacks with flip-block, flip-inline, both together, or flip-start. The browser then tries another side when the first one would overflow. Two optional lines set width: anchor-size(width) and position-visibility: anchors-visible. Here is a worked example. With the anchor --trigger, top center, an 8px gap and flip-block ticked, the tooltip rule reads position-area: top center, then margin-bottom: 8px, then position-try-fallbacks: flip-block. Near the top of the viewport, the browser can flip the tooltip below the button. The live preview uses your browser's own support, checked with CSS.supports. When your browser lacks anchor positioning, the preview is replaced by a note. Support differs between browsers and versions, so check MDN or caniuse before shipping, and keep a fallback. The output uses the fixed class names .trigger and .tooltip, which you rename to fit your markup. The tool does not generate @position-try blocks, anchor() inset functions or popover HTML.

Front-end developers building tooltips, menus and popovers with plain CSS. The tool runs entirely in your browser, so your data never leaves your device.

02How to use CSS Anchor Positioning Generator

  1. Type an anchor name that starts with two dashes, such as --trigger
  2. Click a cell in the grid, or choose vertical and horizontal values from the dropdowns
  3. Set the gap and tick the fallbacks you want
  4. Check the live preview if your browser supports it
  5. Copy the CSS and add the class names to your trigger and floating element

03Worked examples

Input: Anchor --trigger, top center, gap 8px, fallback flip-block
Result: .trigger { anchor-name: --trigger; } .tooltip { position: absolute; /* or fixed */ position-anchor: --trigger; position-area: top center; margin-bottom: 8px; position-try-fallbacks: flip-block; }
Input: Anchor --menu-btn, bottom span-right, gap 4px, flip-block and flip-inline, match width, hide with anchor
Result: .trigger { anchor-name: --menu-btn; } .tooltip { position: absolute; /* or fixed */ position-anchor: --menu-btn; position-area: bottom span-right; margin-top: 4px; position-try-fallbacks: flip-block, flip-inline; width: anchor-size(width); position-visibility: anchors-visible; }
Input: Anchor --info, center right, gap 12px, fallback flip-inline, hide with anchor
Result: .tooltip { position: absolute; /* or fixed */ position-anchor: --info; position-area: center right; margin-left: 12px; position-try-fallbacks: flip-inline; position-visibility: anchors-visible; }
A side popover that flips to the left when it runs out of room and hides when the anchor scrolls away. The .trigger rule is trimmed from the output.
Input: Anchor name trigger (no -- prefix), other options default
Result: Error: Anchor name must be a dashed ident such as "--trigger".
anchor-name only accepts a dashed ident, so the tool refuses to produce CSS until the name starts with two dashes.
Input: Anchor --avatar, top right, gap 0, fallback flip-start
Result: .trigger { anchor-name: --avatar; } .tooltip { position: absolute; /* or fixed */ position-anchor: --avatar; position-area: top right; position-try-fallbacks: flip-start; }
A notification badge sitting on the corner of an avatar. With a gap of 0 no margin line is written.

04Common use cases

  • Placing a tooltip above a button that flips below near the top of the viewport
  • Building a dropdown menu that matches its button's width
  • Replacing a JavaScript positioning library for simple popovers
  • Learning what each position-area keyword does by clicking the grid
  • Hiding a floating label when its anchor scrolls out of view

05Tips

  • Give each anchor a unique anchor-name, or the floating element may attach to a different element than you expect
  • Use position: fixed instead of absolute when the floating element lives in the top layer, such as a popover
  • Wrap the rules in @supports (anchor-name: --a) if you keep a JavaScript fallback
  • flip-block swaps top and bottom, while flip-inline swaps left and right

06Related concepts

anchor-name, position-anchor, position-area, position-try-fallbacks, anchor-size(), Popover API.

Frequently Asked Questions

What is CSS Anchor Positioning Generator?

CSS Anchor Positioning Generator is a free, browser-based developer tool on AIDToolStack. Generate CSS anchor positioning code: anchor-name, position-anchor, position-area and position-try-fallbacks, with a live preview where supported. It requires no installation or sign-up and works entirely in your browser.

Is CSS Anchor Positioning Generator free to use?

Yes. No sign-up, no fees and no usage cap.

Does CSS Anchor Positioning Generator store my data?

No. It runs in your browser; nothing is uploaded.

Related Tools

Reviews and commentsShow

Reviews

Sign in to leave a review.

Loading reviews…

Comments

Sign in to leave a comment.

Loading comments…

What changed in AI dev tools, once a month

Renames, shutdowns, pricing changes and new MCP setups, each with a source.

Subscribe