Anchor-scope - CSS Property
Summary of characteristics of the anchor-scope property
anchor-name.none | allnoneDiscrète: during an animation, the anchor-scope property passes from one value to another without transition.Per grammar: serialization in the order of syntax.Syntax diagram of anchor-scope.
anchor-scope property.The links in the diagram provide more details about the values.
Download the diagram.
In the diagram, the bold terms are the predefined words of CSS, the other terms are described below:
--idis an identifier defined byanchor-name. It must start with a double dash.- Multiple IDs can be specified, separated by a comma.
Description of the anchor-scope property.
The property anchor-scope is used in the area of anchor-based positioning. It changes the scope of the property anchor-name.
It's useful when several elements have the same anchor ID.
For the anchor-scope property to work properly, the positioned element needs to be a child of the element that serves as an anchor.
Anchored positioning can still work without this: you can link an element to an anchor even if there's no parent-child relationship between them.
But in that case, the anchors have to have a unique ID, which isn't always possible when elements are generated automatically.
Let's take the example of a series of images showing different means of transportation. Each image gets a tooltip. All these images have the same anchor ID.
In this first example (without using anchor-scope), you can see that all the tooltips overlap because they all position themselves relative to the
last image.
In this second example, the property anchor-scope was used, limiting its scope to each of the images. The tooltips are correctly positioned.
Also see the anchor-name property for a summary of useful properties for anchor positioning. You'll also find a tutorial on anchor positioning
on this page.
Values for anchor-scope.
- anchor-scope: none;
No change in the scope of anchor IDs.
- anchor-scope: all;
Specifies that all positioning IDs are now limited to the descendant tree of the element that receives this property. One exception though: IDs that are already limited by a
anchor-scopeproperty. - anchor-scope: --id;
Specifies the scope of the
--ididentifier. This is now limited to the element that receives this property and its sub-tree (descendant tree).Several IDs can be specified, separated by a comma.
- anchor-scope: initial; (
none) anchor-scope: inherit; anchor-scope: revert; anchor-scope: revert-layer; anchor-scope: revert-rule; anchor-scope: unset;Common values are presented on these pages:
initial,inherit,revert,revert-layer,revert-rule,unset.
Animation of the anchor-scope property.
The property anchor-scope can be animated in the discrete animation type, meaning it jumps from one value to another without any transition.
Simulator.
The position ID set on each of the first three images is --demo1. The following ones got --demo2.
Each of the labels already refers to one of the IDs to position itself. All that's left is to define anchor-scope.
Browsers compatibility with anchor-scope.
The anchor-scope property is well recognized by all modern browsers.
anchor-scope property.Notes:
(1) Samsung Internet does not support the position-anchor property with the value normal.anchor-visibility property.
(2) Android browser does not support the position-anchor property with the value normal.
It also doesn't fully support the anchor-visibility property.
(3) Doesn't fully support the anchor-visibility property.
(4) Firefox does not allow animation of the anchor() and anchor-size() functions.
It does not fully support the anchor-visibility property.
(5) Opera does not support the position-anchor property with the value normal.
It also doesn't fully support the anchor-visibility property.
positioning
anchor-scopeproperty
Browsers on computers :
Mobile browsers :
Outdated or marginal browsers :

Internet Explorer

UC Browser pour Androïd

Opéra Mobile

QQ Browser

Baidu Browser

Samsung Internet

Androïd Brower

Chrome

Chrome pour Androïd

Edge

Firefox

Firefox pour Androïd

KaiOS Browser

Opéra

Safari

Safari sur IOS

Opéra mini
Historic of the anchor-scope property.
-
CSS Anchor Positioning - Level 1
Absolute positioning relative to the page or screen can prove to be limited when you want to position an element relative to another.
This specification describes the properties necessary to achieve this, as well as the functionsanchor()andanchor-size()that allow you to set the position and dimensions of an element based on another.
It also describes how to test several positioning possibilities to adapt to the context, particularly to the state of the page scrolling.Regardinganchor-scopeFirst definition of the propertyanchor-scope.June 29, 2023Working Draft.
See also, about anchor positioning.
Anchor positioning is a relatively new feature, described in the specification CSS Anchor Positioning. The following properties are also described in this module.
Properties:
anchor-name.position-try-fallbacks and position-try-order.position-try-fallbacks.


