<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>301919</bug_id>
          
          <creation_ts>2025-11-04 02:41:05 -0800</creation_ts>
          <short_desc>[css-anchor-position-1] Chain of three or more anchor-positioned elements doesn&apos;t work</short_desc>
          <delta_ts>2026-03-25 19:26:42 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>Layout and Rendering</component>
          <version>WebKit Nightly Build</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          <see_also>https://github.com/web-platform-tests/wpt/pull/58650</see_also>
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          <blocked>291856</blocked>
          <everconfirmed>1</everconfirmed>
          <reporter name="Roman Komarov">kizmarh</reporter>
          <assigned_to name="Kiet Ho">kiet.ho</assigned_to>
          <cc>arpit.agrawal2502</cc>
    
    <cc>bfulgham</cc>
    
    <cc>eric</cc>
    
    <cc>fantasai.bugs</cc>
    
    <cc>kiet.ho</cc>
    
    <cc>maikelkrause</cc>
    
    <cc>simon.fraser</cc>
    
    <cc>webkit-bug-importer</cc>
    
    <cc>zalan</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>2156220</commentid>
    <comment_count>0</comment_count>
      <attachid>477285</attachid>
    <who name="Roman Komarov">kizmarh</who>
    <bug_when>2025-11-04 02:41:05 -0800</bug_when>
    <thetext>Created attachment 477285
Saved HTML from the CodePen example

To reproduce: https://codepen.io/kizu/pen/JoGzMzW or see the attached copy of the test&apos;s HTML.

Expected: elements go in a “chain” one after another, anchoring to the last acceptable anchor. I remember this was decided in this issue: https://github.com/w3c/csswg-drafts/issues/8165

Both in Chrome and Firefox Nightly it is currently possible to anchor an absolutely positioned element to another absolutely positioned element if it is earlier in the flat tree. But in Safari (both stable and TP), it doesn&apos;t work correctly. In addition, when resizing the viewport vertically after the first time the page renders, the positioning of elements can adjust even though there is nothing that should cause it.

I noticed this issue in my old article&apos;s sidenotes layout example: https://kizu.dev/anchor-positioning-experiments/#sidenotes-layout

Eric Meyer also independently stumbled on this issue when testing in Safari for a similar use case: https://mastodon.social/@Meyerweb/115488981393573478</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2156271</commentid>
    <comment_count>1</comment_count>
    <who name="Eric Meyer">eric</who>
    <bug_when>2025-11-04 06:15:17 -0800</bug_when>
    <thetext>I discovered that changing this line in my testcase (https://codepen.io/meyerweb/pen/zxreeZE):

```
	top: max(anchor(var(--for) top), calc(anchor(--sidenote bottom) + 0.67em));
```

…to this, adding a fallback value to the `anchor()` function :

```
	top: max(anchor(var(--for) top), calc(anchor(--sidenote bottom, 0px) + 0.67em));

```

…resolved the unwanted layout behavior, though it does not do so in Roman’s testcase.  The layout in his testcase shifted a bit when the fallback was added, but still had the list items overlapping each other.  Crucially,  in my testcase the fallback value has to have a unit: setting it to unitless `0` did nothing to resolve the problem shown.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2157887</commentid>
    <comment_count>2</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2025-11-11 02:42:11 -0800</bug_when>
    <thetext>&lt;rdar://problem/164468098&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2162301</commentid>
    <comment_count>3</comment_count>
    <who name="Roman Komarov">kizmarh</who>
    <bug_when>2025-12-01 13:54:01 -0800</bug_when>
    <thetext>Stumbled over another case: https://codepen.io/kizu/pen/NPNBBGd — when one of the anchors in the chain anchors to multiple anchors, the initial state is broken if there are many anchors. Removing some of the anchors from the `min()` there fixes the issue, but only partially — after resizing one of the inner elements, things break again.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2185990</commentid>
    <comment_count>4</comment_count>
    <who name="">maikelkrause</who>
    <bug_when>2026-03-01 11:36:12 -0800</bug_when>
    <thetext>I ran into the same thing while working on this demo which uses a chain with two separate anchors: https://codepen.io/maikelkrause/pen/yyaNQYg

And a simplified test case (this one with just one anchor chain): https://codepen.io/maikelkrause/pen/raMOVNN

Interestingly the result seems to be non-deterministic. I get the elements rendered in different sequences when I refresh the page a few times.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2191216</commentid>
    <comment_count>5</comment_count>
    <who name="">arpit.agrawal2502</who>
    <bug_when>2026-03-17 19:55:17 -0700</bug_when>
    <thetext>I also hit the same issue.

Test case: https://codepen.io/editor/arpit-codes/pen/019cf6ad-f414-76e9-b490-f355482cac4b

In the above pen, the first container shows that starting the chain with a static element also leads to the wrong behaviour.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2191787</commentid>
    <comment_count>6</comment_count>
    <who name="Kiet Ho">kiet.ho</who>
    <bug_when>2026-03-19 11:04:04 -0700</bug_when>
    <thetext>Pull request: https://github.com/WebKit/WebKit/pull/60946</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2192112</commentid>
    <comment_count>7</comment_count>
    <who name="Kiet Ho">kiet.ho</who>
    <bug_when>2026-03-20 10:58:37 -0700</bug_when>
    <thetext>Submitted web-platform-tests pull request: https://github.com/web-platform-tests/wpt/pull/58650</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2192198</commentid>
    <comment_count>8</comment_count>
    <who name="Kiet Ho">kiet.ho</who>
    <bug_when>2026-03-20 15:23:06 -0700</bug_when>
    <thetext>@maikelkrause@gmail.com: This test case https://codepen.io/maikelkrause/pen/raMOVNN actually has two bugs: this (which will fix the green chain) and bug 310398 (which will fix the purple chain)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2192204</commentid>
    <comment_count>9</comment_count>
    <who name="">maikelkrause</who>
    <bug_when>2026-03-20 15:46:16 -0700</bug_when>
    <thetext>Thanks for looking into it Kiet Ho! I&apos;ll leave a comment on the other ticket also.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2193166</commentid>
    <comment_count>10</comment_count>
    <who name="EWS">ews-feeder</who>
    <bug_when>2026-03-24 10:28:24 -0700</bug_when>
    <thetext>Committed 309845@main (28a802021ac6): &lt;https://commits.webkit.org/309845@main&gt;

Reviewed commits have been landed. Closing PR #60946 and removing active labels.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2193716</commentid>
    <comment_count>11</comment_count>
    <who name="EWS">ews-feeder</who>
    <bug_when>2026-03-25 19:26:42 -0700</bug_when>
    <thetext>Committed 305413.579@safari-7624-branch (7a468b09d94a): &lt;https://commits.webkit.org/305413.579@safari-7624-branch&gt;

Reviewed commits have been landed. Closing PR #4821 and removing active labels.</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="0"
              isprivate="0"
          >
            <attachid>477285</attachid>
            <date>2025-11-04 02:41:05 -0800</date>
            <delta_ts>2025-11-04 02:41:05 -0800</delta_ts>
            <desc>Saved HTML from the CodePen example</desc>
            <filename>Chain of anchored elements.html</filename>
            <type>text/html</type>
            <size>626</size>
            <attacher name="Roman Komarov">kizmarh</attacher>
            
              <data encoding="base64">PCFET0NUWVBFIGh0bWw+CjxodG1sIGxhbmc9ImVuIiBkYXRhLWx0LWluc3RhbGxlZD0idHJ1ZSI+
PGhlYWQ+CjxtZXRhIGh0dHAtZXF1aXY9ImNvbnRlbnQtdHlwZSIgY29udGVudD0idGV4dC9odG1s
OyBjaGFyc2V0PVVURi04Ij4KICA8bWV0YSBjaGFyc2V0PSJVVEYtOCI+CiAgCiAgCiAgCgogIDx0
aXRsZT5DaGFpbiBvZiBhbmNob3JlZCBlbGVtZW50czwvdGl0bGU+CgogICAgPGxpbmsgcmVsPSJj
YW5vbmljYWwiIGhyZWY9Imh0dHBzOi8vY29kZXBlbi5pby9raXp1L3Blbi9Kb0d6TXpXIj4KICAK
ICAKICAKICAKPHN0eWxlPgoudGVzdCB7CiAgcG9zaXRpb246IGFic29sdXRlOwogIGFuY2hvci1u
YW1lOiAtLXRlc3Q7CiAgdG9wOiBhbmNob3IoLS10ZXN0IGJvdHRvbSk7CgogIHBhZGRpbmc6IDFl
bTsKICBtYXJnaW46IDFlbTsKICBib3JkZXI6IHNvbGlkOwp9Cjwvc3R5bGU+CgogIAogIAogIAo8
L2hlYWQ+Cgo8Ym9keT4KICA8b2w+CiAgPGxpIGNsYXNzPSJ0ZXN0Ij50ZXN0PC9saT4KICA8bGkg
Y2xhc3M9InRlc3QiPnRlc3Q8L2xpPgogIDxsaSBjbGFzcz0idGVzdCI+dGVzdDwvbGk+CiAgPGxp
IGNsYXNzPSJ0ZXN0Ij50ZXN0PC9saT4KPC9vbD4KICAKICAKICAKCgoKPC9ib2R5PjwvaHRtbD4=
</data>

          </attachment>
      

    </bug>

</bugzilla>