CSS anchor-scope Property
The anchor-scope property limits where named CSS anchors can be referenced, restricting anchor associations to a particular element and its descendants.
It is especially useful for repeated components, such as cards, menus, and tooltips, that reuse the same anchor names. By defining a scope, each component can reference its own anchors without interfering with other components.
anchor-scope Syntax
selector {
anchor-scope: --my-anchor;
}
The property accepts none, all, or one or more comma-separated anchor names beginning with two hyphens.
.component {
anchor-scope: all;
}
.card {
anchor-scope: --card-anchor, --label-anchor;
}
The property also accepts the global CSS values inherit, initial, revert, revert-layer, and unset.
Property Values
| Value | Description |
|---|---|
none |
Does not establish an anchor scope. This is the initial value. |
all |
Limits all named anchors defined within the subtree to anchor associations within that subtree, subject to nested scopes. |
--anchor-name |
Limits the specified anchor name to the element's subtree. |
--first, --second |
Limits multiple named anchors using a comma-separated list. |
Named values use the CSS <dashed-ident> data type and must begin with two hyphens. The names are not enclosed in quotation marks.
The property applies to all elements, is not inherited, and has an initial value of none. Its animation type is discrete.
How anchor-scope Works
CSS anchor positioning allows a positioned element to reference another element through a shared anchor name.
Without an explicit scope, multiple elements using the same anchor name can create unexpected associations. When several eligible anchors share a name, a positioned element generally uses the last matching anchor in document order unless an eligible ancestor anchor takes precedence.
The anchor-scope property restricts which named anchors are visible to positioned elements. A typical setup involves three steps:
- Apply
anchor-scopeto the component container. - Assign an
anchor-nameto an element inside the container. - Reference that name from a positioned element inside the same scope.
.component {
anchor-scope: --trigger;
}
.trigger {
anchor-name: --trigger;
}
.popup {
position: absolute;
position-anchor: --trigger;
position-area: bottom;
}
When the trigger and popup belong to the same component subtree, the popup can use that component's named anchor without accidentally referencing an anchor from another scoped component.
The property does not position elements by itself. It controls which named anchor associations are allowed.
Scoping Named Anchors
Use a specific anchor name when only one named anchor should be restricted within a component.
.menu {
anchor-scope: --menu-trigger;
}
.menu-button {
anchor-name: --menu-trigger;
}
.menu-panel {
position: absolute;
position-anchor: --menu-trigger;
position-area: bottom;
}
With this setup, the --menu-trigger name is scoped to the menu subtree. Positioned elements outside that scope cannot use the menu's named anchor.
Other anchor names that are not included in the anchor-scope declaration remain unaffected by that particular scope.
This selective approach is useful when a component needs to keep some anchors private while allowing other named anchors to participate in associations elsewhere.
Scoping All Anchors
The all keyword restricts all named anchors defined within the subtree, rather than requiring each name to be listed individually.
.card {
anchor-scope: all;
}
.card-title {
anchor-name: --card-title;
}
.card-button {
anchor-name: --card-button;
}
.card-tooltip {
position: absolute;
position-anchor: --card-button;
position-area: top;
}
Both --card-title and --card-button are scoped within the card. Other components can reuse these names without their positioned elements referencing anchors inside this card.
The all value is convenient for self-contained components with several named anchors.
Nested elements that establish their own anchor scopes can further restrict associations within their subtrees.
Multiple Anchor Names
You can scope several specific anchor names by separating them with commas.
.panel {
anchor-scope: --heading, --action;
}
.panel-heading {
anchor-name: --heading;
}
.panel-button {
anchor-name: --action;
}
.panel-note {
anchor-name: --note;
}
The --heading and --action names are restricted to the panel's subtree. The --note name is not restricted by this declaration.
This provides more precise control than anchor-scope: all when only selected anchor names need to be isolated.
anchor-scope Example
The following example creates two cards that reuse the same anchor name. Each card establishes its own scope so its information label is positioned relative to its own button.
<div class="scope-demo">
<div class="scope-card">
<button type="button" class="scope-button">Card One</button>
<span class="scope-label">Information One</span>
</div>
<div class="scope-card">
<button type="button" class="scope-button">Card Two</button>
<span class="scope-label">Information Two</span>
</div>
</div>
.scope-demo {
display: flex;
flex-wrap: wrap;
gap: 20px;
}
.scope-card {
position: relative;
anchor-scope: --card-button;
width: 200px;
min-height: 140px;
padding: 15px;
border: 1px solid #ccc;
box-sizing: border-box;
}
.scope-button {
anchor-name: --card-button;
padding: 8px 12px;
border: 0;
background-color: #1769aa;
color: #fff;
}
.scope-label {
position: absolute;
position-anchor: --card-button;
position-area: bottom;
margin-top: 8px;
padding: 6px 10px;
background-color: #eaf3fa;
border: 1px solid #1769aa;
color: #333;
white-space: nowrap;
}
Both cards use --card-button, but anchor-scope keeps each anchor association within its own card.
In supporting browsers, each information label appears below the button in its own card. Without anchor-scope, the repeated anchor name could cause both labels to reference the same eligible anchor.
Older browsers that do not support anchor positioning may display the labels differently. Provide a suitable fallback when their placement is essential to the interface.
anchor-scope vs. anchor-name
These properties work together, but each has a different responsibility.
| Property | Purpose |
|---|---|
anchor-name |
Assigns one or more names to an element so positioned elements can reference it. |
anchor-scope |
Limits which elements can use named anchors within a particular subtree. |
position-anchor |
Associates a positioned element with its default named anchor. |
Use anchor-name to create the reference, anchor-scope to control its visibility, and position-anchor to connect the positioned element to that reference.
Important Considerations
Keep the following points in mind when using anchor-scope:
- Repeated components: Scoping allows multiple components to reuse the same anchor names without unintended cross-component associations.
- Subtree boundaries: Named anchors restricted by a scope cannot be referenced by positioned elements outside that scope.
- Specific names: A comma-separated list restricts only the named anchors included in that list.
- Implicit anchors: The property does not affect implicit anchor associations established by features such as popover invokers.
- Browser compatibility: The related anchor positioning properties must also be supported for the complete layout to work.
Use anchor-scope when anchor names need to be reused safely or when a component should keep its named anchors isolated from the rest of the document.
Browser Support
The anchor-scope property has Baseline 2026 Newly available status. It is supported in the latest major browser versions, but older browsers may not recognize it.
Visit Can I Use? to check current compatibility. Also check support for anchor-name, position-anchor, and position-area when using them together.
Specifications
The anchor-scope property is defined in the CSS Anchor Positioning Module Level 1 specification.
