Anchoring Footnote Bubbles to a Post
The State of CSS 2024 results put CSS Anchor Positioning in the survey's Top 4, with Scroll-Driven Animations right behind it. Both ship good developer experience on their own; used together they cover ground that would have required JavaScript not long ago. The demo below pops footnotes out as side comments on a blog post, with three requirements: show each footnote when it enters the screen, attach it to its referring text, and fall back gracefully on mobile where there are no side margins.
Markup: A Post With Notes
The starting point is a standard post layout — title, cover image, body text — where some paragraphs end in a footnote:
<main class="post">
<!-- etc. -->
<p class="note">
Super intereseting information!
<span class="footnote"> A footnote about it </span>
</p>
</main>
Anchor Positioning Basics
Out of the box the footnotes sit inline inside the body, right after the text they annotate. The goal is floating bubbles pinned to the sides of the post. Two terms matter throughout:
- Anchor — the element used as a positioning reference, identified by an anchor name.
- Target — the absolutely-positioned element placed relative to one or more anchors (often just called an "absolutely positioned element" elsewhere).
Choosing the Anchor and Target
Each .footnote is clearly the target. The anchor choice is less obvious: rather than making each .note an anchor, use the whole .post. Setting .footnote to position: absolute shows why — the footnotes leave the normal document flow and already hover above their .note elements, so they're aligned vertically. Only horizontal placement onto the sides remains.
.footnote {
position: absolute;
}
Registering the Anchor
Simply setting the sides would need an inset value, and any such value is a magic number: it depends on the viewport and on the footnote's own content, which changes its width. Instead, register the post as an anchor with the anchor-name property, which takes a dashed-ident (a custom name starting with two dashes):
.post {
anchor-name: --post;
}
Then point the target at it with position-anchor, passing the anchor's dashed ident and keeping absolute positioning. That makes .post the default anchor for the following step:
.footnote {
position: absolute;
position-anchor: --post;
}
Placing the Target on the Sides
The anchor() function returns a <length> value for one side of the anchor, so the inset properties stay correct without hard-coded numbers. Connect the target's left side to the anchor's right side, and vice versa:
.footnote {
position: absolute;
position-anchor: --post;
/* To place them on the right */
left: anchor(right);
/* or to place them on the left*/
right: anchor(left);
/* Just one of them at a time! */
}
The target then sticks directly to the post's edge, so margin adds breathing room the usual way. A dash of extra styling makes it look presentable:
.footnote {
/* ... */
background-color: #fff;
border-radius: 20px;
margin: 0px 20px;
padding: 20px;
}
To split footnotes across both sides, select even and odd notes with nth-of-type() and flip their insets — and drop the final inset declaration from .footnote itself:
.note:nth-of-type(odd) .footnote {
left: anchor(right);
}
.note:nth-of-type(even) .footnote {
right: anchor(left);
}
nth-of-type() is the right selector rather than nth-child, since iteration should cover only .note elements, not every sibling.
Animating the Entrance
Fold the ordinary @keyframes making footnotes grow from invisible to full size into the flow like so:
@keyframes pop-up {
from {
opacity: 0;
transform: scale(0.5);
}
to {
opacity: 1;
}
}
Apply it to each .footnote:
.footnote {
/* ... */
animation: pop-up linear;
}
Alone, this does nothing — normally animation-duration would start the clock. View-driven animations don't advance over a fixed duration; progression tracks the element's position on screen instead. Point animation-timeline at view():
.footnote {
/* ... */
animation: pop-up linear;
animation-timeline: view();
}
That ends the animation exactly as the element leaves the viewport, which is too late to be readable. Constrain it with animation-range set to cover 0% cover 40%: the animation starts when the element is 0% in view and finishes at 40% in view.
.footnote {
/* ... */
animation: pop-up linear;
animation-timeline: view();
animation-range: cover 0% cover 40%;
}
Mobile Fallback
On small screens there's no room beside the post, so the footnotes must return to reading as normal inline notes. Gate the side-comment layout behind a viewport threshold of roughly 1000px; below that, they display in the body like any other footnote.
.footnote {
display: flex;
gap: 10px;
border-radius: 20px;
padding: 20px;
background-color: #fce6c2;
&::before {
content: "Note:";
font-weight: 600;
}
}
@media (width > 1000px) {
/* Styles */
}
Outcome
The comments appear on the sides only when space allows. The result is a dynamic way to surface extra context paragraph by paragraph, achieved in CSS alone.



