Anchor-scope - CSS Property

anchor-scope

Summary of characteristics of the anchor-scope property

Quick description
Defines the scope of the property anchor-name.
Status
Standard
Predefined values
none | all
Percentages
Not applicable.
Initial value
none
Inherited by default
No.
Discrète: during an animation, the anchor-scope property passes from one value to another without transition.
Per grammar: serialization in the order of syntax.
W3C Module
CSS Anchor Positioning
Document status: WD (Working Draft)

Syntax diagram of anchor-scope.

Anchor-scope property - Syntax diagramSyntax diagram of the anchor-scope CSS property, which defines the scope of the element used as an anchor (anchor positioning). none none all all --id --id , ,anchor-scope:;anchor-scope:;
Syntax diagram of the 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:

  • --id is an identifier defined by anchor-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.

🚍
Bus
🚂
Train
🛫
Plane


In this second example, the property anchor-scope was used, limiting its scope to each of the images. The tooltips are correctly positioned.

🚍
Bus
🚂
Train
🛫
Plane



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-scope property.

  • anchor-scope: --id;

    Specifies the scope of the --id identifier. 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.

🍉
Watermelon
🍓
Strawberry
🍅
Tomato

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.

anchor-scope :
🍇
Grape
🍌
Banana
🥑
Lawyer
🥝
Kiwi
🥭
Mango
🍋
Lemon
 

Browsers compatibility with anchor-scope.

The anchor-scope property is well recognized by all modern browsers.

Column 1
General support for anchor positioning.
Column 2
Support for the anchor-scope property.

Notes:

(1) Samsung Internet does not support the position-anchor property with the value normal. It also doesn't fully support the 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.

1
Anchoring
positioning
2
anchor-scope
property
Estimated overall support.
86%
69%

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 functions anchor() and anchor-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.

    Regarding anchor-scope First definition of the property anchor-scope.
    WD
    June 29, 2023
    Working Draft.
    CR
    PR
    REC

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
Sets an ID for the item, which can then become an anchor, in the context of anchor positioning.
Anchor-scope
Defines the scope of the property anchor-name.
position-anchor
Defined in relation to which anchor the element should be positioned.
position-area
Defines how an element is positioned relative to the anchor (above, beside, etc.).
position-try
Shorthand property that summarizes the values for position-try-fallbacks and position-try-order.
position-try-fallbacks
Specifies a list of positions for the positioned element (anchoring positioning) so that the browser can choose the one that is most suitable at any given moment, taking into account scrolls or zooms.
position-try-order
Defines a different order for the values listed by position-try-fallbacks.
position-visibility
Defines whether the positioned element is visible or not, in the context of anchoring positioning.

Functions:

anchor()
Returns the position of one of the edges of the element designated as the anchor (anchor-based positioning).
anchor-size()
Returns the size (height or width) of the element designated as the anchor (anchor-based positioning).

At-rules:

@position-try
Defines a set of rules for each anchor position and gives them a name (anchoring positioning).