Skip to content
Tutorials Center
My learning

Topics

CSS Reference ยท Positioning and Stacking

The anchor-name property

Reference for the CSS anchor-name property: name an element as an anchor so other elements can be positioned relative to it. Syntax, example and support.

The anchor-name property turns an element into an anchor by giving it one or more names. Another element, absolutely or fixed positioned, can then be placed next to it with position-anchor, position-area or the anchor() function, without JavaScript measuring any rectangles.

Names are dashed identifiers: they must start with two hyphens, like custom properties.

CSS
.help-button { anchor-name: --help; }

Try it

Naming an anchor

Syntax

CSS
anchor-name: none | <dashed-ident>#;

anchor-name: --menu-button;
anchor-name: --a, --b;     /* two names for one element */
  • Initial value: none
  • Applies to: all elements that generate a box
  • Inherited: no
  • Animatable: no (discrete)
  • Computed value: as specified

Values

Value Description
none The element is not an anchor.
<dashed-ident> A name starting with --. A comma-separated list gives the element several names.

Usage notes

  • Names are scoped to the tree. An anchor is found by name within the same tree scope. If several elements share a name, the last one before the positioned element in tree order is used, so give each anchor a unique name (set it per element, for example with an inline style).
  • Only for positioned elements. The element that uses the anchor must be position: absolute or fixed, and an anchor must be a valid candidate (for instance, not in a hidden subtree or skipped by content-visibility).
  • Popover and <dialog> use. Naming the invoking button as an anchor lets a popover sit next to it while still living in the top layer.
  • Not a fix for layout. Anchoring changes where a box is drawn, not the document order, so keyboard and screen reader order stay as in the HTML.
  • Provide a fallback. Ensure the positioned element is still usable when it ends up at its static position.

Browser support

Anchor positioning is a relatively new feature. Chromium browsers support it from version 125 and Safari from version 26; support elsewhere is still arriving, so check a current compatibility table and add a fallback before relying on it.