CSS anchor-name Property

The anchor-name property assigns one or more names to an element so other elements can use it as a reference for CSS anchor positioning.

Named anchors allow positioned elements, such as tooltips, labels, and information panels, to be placed relative to another element without calculating its coordinates in JavaScript.

anchor-name Syntax

selector {
  anchor-name: --my-anchor;
}

An anchor name is a custom identifier beginning with two hyphens. Multiple names can be assigned using a comma-separated list.

.target {
  anchor-name: --first-anchor, --second-anchor;
}

The property also accepts the global CSS values inherit, initial, revert, revert-layer, and unset.

Property Values

Value Description
none Does not assign an anchor name to the element. This is the initial value.
--anchor-name Assigns a custom anchor name that other positioned elements can reference.
--first, --second Assigns multiple comma-separated anchor names to the same element.

Anchor names use the CSS <dashed-ident> data type. They are identifiers, not quoted strings, and must begin with two hyphens.

The property is not inherited. Its initial value is none, and its animation type is discrete.

How anchor-name Works

CSS anchor positioning connects an anchor element to another element that needs to be positioned relative to it.

A typical setup involves three steps:

  1. Assign a name to the reference element using anchor-name.
  2. Associate an absolutely or fixed-positioned element with that name using position-anchor.
  3. Choose its location relative to the anchor using position-area or the anchor() function.
.anchor {
  anchor-name: --reference;
}
.positioned {
  position: absolute;
  position-anchor: --reference;
  position-area: bottom;
}

Here, the positioned element is associated with the named anchor and placed below it.

The anchor-name property only defines the anchor. It does not change the anchor element's own position or automatically move other elements.

Naming Anchors

Anchor names must begin with two hyphens, following the same general naming pattern used by CSS custom properties.

.help-button {
  anchor-name: --help-button;
}
.menu-trigger {
  anchor-name: --menu-trigger;
}
.card-heading {
  anchor-name: --card-heading;
}

Choose descriptive names that identify the element's role. For example, --help-button is easier to understand than --a1 when reviewing a stylesheet.

Anchor names do not have to be unique throughout a document. However, using the same name for multiple elements can affect which anchor a positioned element references.

When multiple eligible elements share a name, the browser generally selects the nearest eligible ancestor anchor, if one exists, or otherwise the last eligible matching anchor in document order. The anchor-scope property can limit anchor associations within a particular subtree.

Positioning with Anchors

After naming an anchor, use position-anchor on an absolutely or fixed-positioned element to establish the association.

.trigger {
  anchor-name: --trigger;
}
.tooltip {
  position: absolute;
  position-anchor: --trigger;
  position-area: top;
}

The tooltip is positioned above the anchor using position-area: top.

For more precise positioning, the anchor() function can reference an anchor's edges.

.tooltip {
  position: absolute;
  position-anchor: --trigger;
  top: anchor(bottom);
  left: anchor(left);
}

In this example, the tooltip's top edge is positioned at the anchor's bottom edge, while its left edge aligns with the anchor's left edge.

Using anchor() allows a positioned element to follow the anchor's location as the layout changes, without manually calculating pixel offsets.

Multiple Anchor Names

A single element can be assigned more than one anchor name.

.reference {
  anchor-name: --tooltip-anchor, --label-anchor;
}
.tooltip {
  position: absolute;
  position-anchor: --tooltip-anchor;
  position-area: top;
}
.label {
  position: absolute;
  position-anchor: --label-anchor;
  position-area: bottom;
}

Both positioned elements reference the same anchor element using different names. This can be useful when a component provides several independently positioned elements.

Multiple names are separated by commas. A space-separated list without commas is not valid for anchor-name.

anchor-name Example

The following example places an information label below a button using CSS anchor positioning.

<div class="anchor-demo">
  <button type="button" class="anchor-button">Help</button>
  <div class="anchor-label">Additional information</div>
</div>
.anchor-demo {
  position: relative;
  min-height: 150px;
  padding: 20px;
  border: 1px solid #ccc;
}
.anchor-button {
  anchor-name: --help-anchor;
  padding: 8px 16px;
  border: 0;
  background-color: #1769aa;
  color: #fff;
  cursor: pointer;
}
.anchor-label {
  position: absolute;
  position-anchor: --help-anchor;
  position-area: bottom;
  margin-top: 8px;
  padding: 8px 12px;
  background-color: #eaf3fa;
  border: 1px solid #1769aa;
  color: #333;
}

The button defines the anchor using anchor-name: --help-anchor. The information label references that name and uses position-area: bottom to appear below the button.

Browser Result
Additional information

In browsers that support CSS anchor positioning, the label is positioned relative to the button. In older browsers, the anchor positioning declarations may be ignored, so the label can appear in a different location.

anchor-name vs. position-anchor

These two properties work together, but they are applied to different elements.

Property Purpose
anchor-name Defines an element as a named anchor that other elements can reference.
position-anchor Associates an absolutely or fixed-positioned element with its default anchor.

Use anchor-name on the reference element and position-anchor on the element that should be positioned relative to it.

Other anchor positioning features, such as position-area and anchor(), determine where the positioned element appears.

Browser Support

The anchor-name property has Baseline 2026 Newly available status. It is supported across the latest major browser versions, but older browsers may not support it, and some related anchor positioning features have different compatibility requirements.

Visit Can I Use? to check current browser compatibility. Test position-anchor and position-area as well when using them together.

Specifications

The anchor-name property is defined in the CSS Anchor Positioning Module Level 1 specification.

CSS Anchor Positioning Module Level 1