You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[css-anchor-position-1] relaxing abspos ordering requirement for acceptable anchor elements #13751
This gets into very difficult issues very quickly unfortunately.
I've previously thought about this fairly deeply - e.g. if we could sort things ahead of time to determine a better order, but the only thing that works reliably is tree-order unfortunately.
Anchors can be anywhere within a subtree, and you don't know what anchor-names it might have until after you've laid-out that subtree (the 2nd anchor in the above anchor may appear/disappear depending on the container-query evaluation).
Changing the order of the first two divs in the above example will result in different layout.
To that you might say - "ok I'm fine with breaking above just adjust objects being laid out by the containing block based on their top level styles".
First off - compat, second consider:
Again abspos elements may appear/disappear due to their parent changing size, the fixedpos above may appear/disappear in the containing-block list based on how the container-query evaluates. Again tree-order is somewhat the only thing that makes sense here.
Additionally due to position-try-fallbacks you can switch between being anchor-positioned and not depending on what fallback you use (you may have a fallback that doesn't reference any anchors and visa versa).
So what to do.
Note this issue is typically the "worst" when you have abspos referring to other abspos. This broadly isn't an issue for abspos referring to an inflow as the inflow will always be laid-out first. E.g. you are more likely to run into this for demo building purposes counter-intuitively.
Activity
jensimmons commentedon Apr 1, 2026
Here's more: https://frontendmasters.com/blog/the-big-gotcha-of-anchor-positioning/
bfgeek commentedon Apr 1, 2026
This gets into very difficult issues very quickly unfortunately.
I've previously thought about this fairly deeply - e.g. if we could sort things ahead of time to determine a better order, but the only thing that works reliably is tree-order unfortunately.
First off cycles are possible:
For these types of cases you need to rely on tree-order to break the cycles.
To that you might say "ok if something doesn't have any anchor references on itself then layout that first".
Anchors can be anywhere within a subtree, and you don't know what anchor-names it might have until after you've laid-out that subtree (the 2nd anchor in the above anchor may appear/disappear depending on the container-query evaluation).
Changing the order of the first two divs in the above example will result in different layout.
To that you might say - "ok I'm fine with breaking above just adjust objects being laid out by the containing block based on their top level styles".
First off - compat, second consider:
Again abspos elements may appear/disappear due to their parent changing size, the fixedpos above may appear/disappear in the containing-block list based on how the container-query evaluates. Again tree-order is somewhat the only thing that makes sense here.
Additionally due to position-try-fallbacks you can switch between being anchor-positioned and not depending on what fallback you use (you may have a fallback that doesn't reference any anchors and visa versa).
So what to do.
Note this issue is typically the "worst" when you have abspos referring to other abspos. This broadly isn't an issue for abspos referring to an inflow as the inflow will always be laid-out first. E.g. you are more likely to run into this for demo building purposes counter-intuitively.
However a lot of the advanced usecases (chaining abspos off other abspos, see https://meyerweb.com/eric/thoughts/2023/09/12/nuclear-anchored-sidenotes/#fixing-proximate-overlap , or nested menu logic) work due to the tree-order rule.
Any change that we do here has to consider these various cases very carefully to make sure we aren't breaking other use-cases.
In summary a set of constraints:
Broadly speaking devtools for abspos needs to get far better. They suck. A short list of issues I wish browsers (any browser!) would fix:
Ian