Skip to content

Conversation

@chrisdavidmills
Copy link
Contributor

@chrisdavidmills chrisdavidmills commented Dec 4, 2025

Description

Chrome 131 supports the anchor-scope property; see https://chromestatus.com/feature/5094192052436992. It is also supported in Safari 26, and behind a pref in Fx Nightly.

This PR documents anchor-scope.

Motivation

Additional details

Related issues and pull requests

Fixes #39295

@chrisdavidmills chrisdavidmills requested a review from a team as a code owner December 4, 2025 12:30
@chrisdavidmills chrisdavidmills requested review from estelle and removed request for a team December 4, 2025 12:30
@github-actions github-actions bot added the Content:CSS Cascading Style Sheets docs label Dec 4, 2025
@chrisdavidmills chrisdavidmills changed the title Document anchor-scope property Technical review: Document anchor-scope property Dec 4, 2025
@github-actions github-actions bot added the size/m [PR only] 51-500 LoC changed label Dec 4, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Dec 4, 2025

Preview URLs

Flaws (23)

Note! 1 document with no flaws that don't need to be listed. 🎉

URL: /en-US/docs/Web/CSS/Guides/Anchor_positioning/Using
Title: Using CSS anchor positioning
Flaw count: 1

  • unknown:
    • Error parsing /shared-assets/images/diagrams/css/anchor-positioning/position-area.svg: No such file or directory (os error 2)

URL: /en-US/docs/Web/CSS/Reference/Properties/anchor-name
Title: anchor-name
Flaw count: 7

  • broken_links:
    • Link /en-US/docs/Web/CSS/CSS_values_and_units/Value_definition_syntax#single_bar is a redirect
    • Link /en-US/docs/Web/CSS/dashed-ident is a redirect
    • Link /en-US/docs/Web/CSS/CSS_values_and_units/Value_definition_syntax#hash_mark is a redirect
  • macros:
    • Macro cssinfo produces link /en-US/docs/Web/CSS/CSS_cascade/Value_processing which is a redirect
    • Macro cssinfo produces link /en-US/docs/Web/CSS/CSS_cascade/Inheritance which is a redirect
    • Macro cssinfo produces link /en-US/docs/Web/CSS/CSS_cascade/Value_processing which is a redirect
    • Macro cssinfo produces link /en-US/docs/Web/CSS/CSS_animated_properties which is a redirect

URL: /en-US/docs/Web/CSS/Reference/Properties/anchor-scope
Title: anchor-scope
Flaw count: 8

  • broken_links:
    • Link /en-US/docs/Web/CSS/CSS_values_and_units/Value_definition_syntax#single_bar is a redirect
    • Link /en-US/docs/Web/CSS/CSS_values_and_units/Value_definition_syntax#single_bar is a redirect
    • Link /en-US/docs/Web/CSS/dashed-ident is a redirect
    • Link /en-US/docs/Web/CSS/CSS_values_and_units/Value_definition_syntax#hash_mark is a redirect
  • macros:
    • Macro cssinfo produces link /en-US/docs/Web/CSS/CSS_cascade/Value_processing which is a redirect
    • Macro cssinfo produces link /en-US/docs/Web/CSS/CSS_cascade/Inheritance which is a redirect
    • Macro cssinfo produces link /en-US/docs/Web/CSS/CSS_cascade/Value_processing which is a redirect
    • Macro cssinfo produces link /en-US/docs/Web/CSS/CSS_animated_properties which is a redirect

URL: /en-US/docs/Web/CSS/Reference/Properties/position-anchor
Title: position-anchor
Flaw count: 7

  • broken_links:
    • Link /en-US/docs/Web/CSS/CSS_values_and_units/Value_definition_syntax#single_bar is a redirect
    • Link /en-US/docs/Web/CSS/CSS_values_and_units/Value_definition_syntax#single_bar is a redirect
    • Link /en-US/docs/Web/CSS/dashed-ident is a redirect
  • macros:
    • Macro cssinfo produces link /en-US/docs/Web/CSS/CSS_cascade/Value_processing which is a redirect
    • Macro cssinfo produces link /en-US/docs/Web/CSS/CSS_cascade/Inheritance which is a redirect
    • Macro cssinfo produces link /en-US/docs/Web/CSS/CSS_cascade/Value_processing which is a redirect
    • Macro cssinfo produces link /en-US/docs/Web/CSS/CSS_animated_properties which is a redirect

(comment last updated: 2026-01-05 17:06:39)

Copy link
Member

@estelle estelle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops, didn't realize this was in tech review... so sharing my few comments, but will wait til editorial to finish the review

Copy link

@andruud andruud left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@chrisdavidmills
Copy link
Contributor Author

Thanks for the review, @andruud; I'll move this one on to the editorial review stage now.

@chrisdavidmills chrisdavidmills changed the title Technical review: Document anchor-scope property Editorial review: Document anchor-scope property Dec 8, 2025
Copy link
Member

@estelle estelle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry, didn't realize this was ready for review.


For example, if a document contains multiple repeated components, each with a positioned element tethered to an anchor, all the positioned elements will be anchored to the last anchor on the page unless each component uses a different anchor name. This is likely not the desired behavior.

The {{cssxref("anchor-scope")}} property can fix this problem by making it so that each positioned element can only be anchored to an element within the same subtree of the element that has the scope set on it:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about something like:

With the {{cssxref("anchor-scope")}} property, you can limit the visibility, or "scope', of an `anchor-name` value to a specific subtree, which enables the association of multiple same-named anchors with their own positioned elements within a single document:

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the first half of the suggestion, but I felt like the second half was a bit confusing. In the next commit, I've updated it to:

The {{cssxref("anchor-scope")}} property can fix this problem by limiting the visibility, or "scope", of an anchor-name value to a specific subtree. The result is that each positioned element can only be anchored to an element within the same subtree of the element that has the scope set on it:

The {{cssxref("anchor-scope")}} property can fix this problem by making it so that each positioned element can only be anchored to an element within the same subtree of the element that has the scope set on it:

- `anchor-scope: all` sets the scope so that _any_ `anchor-name` values set in the subtree can only be bound to by positioned elements in the same subtree.
- `anchor-scope: --my-anchor` sets the scope so that the specified `anchor-name` value, when set in the subtree, can only be bound to by positioned elements in the same subtree.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggest mentioning none is the default, and somehow alluding to the fact that it can be a comma separated list.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call. I've updated the second bullet to indicate that multiple comma-separated values can be set, and added a third bullet to explain the none value.

- `anchor-scope: all` sets the scope so that _any_ `anchor-name` values set in the subtree can only be bound to by positioned elements in the same subtree.
- `anchor-scope: --my-anchor` sets the scope so that the specified `anchor-name` value, when set in the subtree, can only be bound to by positioned elements in the same subtree.

For example, let's say you have an anchor and a anchor-positioned element inside a scoped container, and another positioned element outside the container:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the intro says this is useful when we have multiple elements with the same anchor name. Let show an example with multiple anchors and positioned elements.

maybe use an ordered list with 3 sets, and do something like

<li>
  <div class="anchor">⚓︎⚓︎⚓︎</div>`
<div class="positioned">Positioned 3</div>
</li>

as the last in the list.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I've rewritten the example to include three sets.

background: orange;
width: fit-content;
padding: 3px;
position: absolute;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

end the hidden part here (i can't add closing tick marks in this editor)

Suggested change
position: absolute;
```css live-sample___anchor-scope
li {
anchor-scope: --my-anchor;
}
.positioned {
position: absolute;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


- `all`: The scope for positioning elements relative to anchor elements that are descendants of the `<section>` elements is limited to positioned elements that are themselves descendants of the `<section>` elements, regardless of the `anchor-name` value used to associate them. As a result, the positioned elements inside the `<section>` elements ("Positioned 1") are anchor-positioned as expected, but the positioned element outside the `<section>` elements ("Positioned 2") is not anchor-positioned. It is out of scope.
- `--my-anchor`: The scope for positioning elements relative to anchor elements that are descendants of the `<section>` elements is limited to positioned elements that are themselves descendants of the `<section>` elements, only if the `--my-anchor` `anchor-name` is used to associate them. As a result, the positioned elements inside the `<section>` elements ("Positioned 1") are anchor-positioned as expected, and the positioned element outside the `<section>` elements ("Positioned 2") is also anchor-positioned as expected. In the former case, the positioned elements are inside the set scope, and in the latter case, the positioned element is not affected by the set scope, as it is using an anchor name outside the scope (<code>&#8209;&#8209;another-anchor</code>). The "Positioned 2" element is positioned relative to the last anchor element in the source that has the matching anchor name.
- `none`: No anchor scope is set on the `<section>` elements. As a result, all of the positioned elements are positioned relative to the last anchor element in the source order.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- `none`: No anchor scope is set on the `<section>` elements. As a result, all of the positioned elements are positioned relative to the last anchor element in the source order.
- `none`: As no anchor scope is set on the `<section>` elements, all of the positioned elements are positioned relative to the last anchor element in the source order.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated


### Comparing different `anchor-scope` values

This example allows you to apply different `anchor-scope` values to multiple containers, to demonstrate the effects of each.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe something like:

This example demonstrates the different `anchor-scope` values by allowing you to apply different `anchor-scope` values to multiple containers, all containing anchors with the same `anchor-name` value.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated


Check out the initial positioning effect applied to the positioned elements with `anchor-scope: all` set on the `<section>` elements, and then try selecting the other available `anchor-scope` values to see what their effect is. You should observe the following:

- `all`: The scope for positioning elements relative to anchor elements that are descendants of the `<section>` elements is limited to positioned elements that are themselves descendants of the `<section>` elements, regardless of the `anchor-name` value used to associate them. As a result, the positioned elements inside the `<section>` elements ("Positioned 1") are anchor-positioned as expected, but the positioned element outside the `<section>` elements ("Positioned 2") is not anchor-positioned. It is out of scope.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move most of these explanations, made more generic, into the description area values section.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't want to do that. I think they are useful here, explained in the context of the example. It is tricky to understand the effects these values have, so this serves as a useful recap.

Copy link
Member

@estelle estelle Jan 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can keep this here, but add the guts to the description, and make this a summary of what is happening, allowing the explanation to be in the description with a "select the [example of the `all` value](#anchor)" lingo with a link to this example

Copy link
Member

@estelle estelle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

left some comments.

I've been thinking about the non-breaking dashes. I think we should stick with regular dashes. breaking double dashes hasn't been an issue thus far on MDN, and they are not valid. https://codepen.io/estelle/pen/WbxwRPa


Anchor scopes only affect **explicit anchor associations**, that is, those made between an anchor element with an `anchor-name` set on it, and a positioned element referencing the anchor element's anchor name in its `position-anchor` value. Anchor scopes do not affect [implicit anchor associations](/en-US/docs/Web/CSS/Guides/Anchor_positioning/Using#implicit_anchor_association).

For more information on anchor features and usage, see the [CSS anchor positioning](/en-US/docs/Web/CSS/Guides/Anchor_positioning) module landing page and the [Using CSS anchor positioning](/en-US/docs/Web/CSS/Guides/Anchor_positioning/Using) guide.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They aren't "landing pages". A landing page serves as a menu, of sorts, for its subpages. #42644 removes the misnomer in the css section

- `anchor-scope: <dashed-ident>#` sets the scope so that the specified `anchor-name` values, when set in the subtree, can only be bound to by positioned elements in the same subtree.
- `anchor-scope: none` is the default value; it specifies that no anchor scoping is set.

If you have, for example, three `anchor-name` values set inside a subtree (say, <code>&#8209;&#8209;anchor1</code>, <code>&#8209;&#8209;anchor2</code>, and <code>&#8209;&#8209;anchor3</code>), setting <code>anchor-scope: &#8209;&#8209;anchor1, &#8209;&#8209;anchor2, &#8209;&#8209;anchor3</code> on the top-level element of the subtree would be equivalent to setting `anchor-scope: all`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
If you have, for example, three `anchor-name` values set inside a subtree (say, <code>&#8209;&#8209;anchor1</code>, <code>&#8209;&#8209;anchor2</code>, and <code>&#8209;&#8209;anchor3</code>), setting <code>anchor-scope: &#8209;&#8209;anchor1, &#8209;&#8209;anchor2, &#8209;&#8209;anchor3</code> on the top-level element of the subtree would be equivalent to setting `anchor-scope: all`.
If you have, for example, three `anchor-name` values set inside a subtree (say, `‑‑anchor1`, `‑‑anchor2`, and `‑‑anchor3`), setting `anchor-scope: ‑‑anchor1, ‑‑anchor2, ‑‑anchor3` on the top-level element of the subtree would be equivalent to setting `anchor-scope: all`.

I used non-breaking hyphens.


#### CSS

We start by specifying our anchor elements as anchors by giving them two {{cssxref("anchor-name")}} values: <code>&#8209;&#8209;my-anchor</code> and `--another-anchor`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking we might want to globally replace all to non-breaking anchor characters, but i don't think a breaking double dash is an issue (we don't do this anywhere else), so i recommend changing all to ndashes and getting rid of the <code>s.

Check out the initial positioning effect applied to the positioned elements with `anchor-scope: all` set on the `<section>` elements, and then try selecting the other available `anchor-scope` values to see what their effect is. You should observe the following:

- `all`: The scope for positioning elements relative to anchor elements that are descendants of the `<section>` elements is limited to positioned elements that are themselves descendants of the `<section>` elements, regardless of the `anchor-name` value used to associate them. As a result, the positioned elements inside the `<section>` elements ("Positioned 1–3") are anchor-positioned as expected, but the positioned element outside the `<section>` elements ("Positioned 4") is not anchor-positioned. It is out of scope.
- `--my-anchor`: The scope for positioning elements relative to anchor elements that are descendants of the `<section>` elements is limited to positioned elements that are themselves descendants of the `<section>` elements, only if the `--my-anchor` `anchor-name` is used to associate them. As a result, the positioned elements inside the `<section>` elements ("Positioned 1–3") are anchor-positioned as expected, and the positioned element outside the `<section>` elements ("Positioned 4") is also anchor-positioned as expected. In the former case, the positioned elements are inside the set scope, and in the latter case, the positioned element is not affected by the set scope, as it is using an anchor name outside the scope (<code>&#8209;&#8209;another-anchor</code>). The "Positioned 4" element is positioned relative to the last anchor element in the source that has the matching anchor name.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add the explanation provided here to the description. Currently, the description does not expand at all on the value section content. Examples should add to what is covered in the description, illustrating what is explained there. The examples should illustrate what was already covered. The content here is good, but will be missed by many readers.


.positioned,
.positioned2 {
background: orange;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

box-shadow: 3px 3px 3px rgba(0 0 0 / .2) does the trick - when 3 are on top of each other it's apparent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Content:CSS Cascading Style Sheets docs size/m [PR only] 51-500 LoC changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CSS Anchor Positioning: anchor-scope documentation missing

3 participants