Multiple Anchor Names on a Single Element
Give one element multiple anchor-name values so several targets can each anchor to a different identifier on the same element.
Detailed Explanation
Why You'd Want This
Imagine an avatar with two anchored decorations: a presence dot at the bottom-right and a notification count at the top-right. They both anchor to the same avatar but conceptually they're different targets. Giving the avatar two anchor names keeps the relationships explicit.
.avatar {
/* Multiple names, comma-separated */
anchor-name: --avatar-corner-tr, --avatar-corner-br;
}
.unread-count {
position: absolute;
position-anchor: --avatar-corner-tr;
position-area: top-end;
transform: translate(40%, -40%);
}
.presence-dot {
position: absolute;
position-anchor: --avatar-corner-br;
position-area: bottom-end;
transform: translate(40%, 40%);
}
Why not just use position-area on one anchor name?
You can! The two-name version is equivalent in this simple case. The benefit appears when:
- The decorations have different lifetimes: maybe
.unread-countis rendered conditionally based on a notification API, while.presence-dotis always present. Distinct names make refactoring safer. - The decorations come from different parts of your component tree: a notification system mounts
.unread-countfrom a global portal, while.presence-dotis rendered inline. Distinct names avoid accidental coupling. - One target needs to follow a different position-area than the other: with one name and
position-areaper target this works, but with two names you can also vary which anchor element each target follows by repointingposition-anchorindependently.
Naming convention
Use semantic names that describe the relationship:
--menu-trigger-1,--menu-trigger-2, ... for repeating trigger buttons--card-handlefor a draggable handle inside a card--row-action-anchorfor a per-row action menu in a table
Avoid --anchor-1, --anchor-2 in production code — once you have 20+ anchor names, semantic names become essential.
Scope and uniqueness
Anchor names are scoped to the document by default. The anchor-scope property (Chrome 131+) lets you scope them to a subtree, which is essential for component libraries: each instance of a tooltip component can use the same internal name without colliding with sibling instances.
Use Case
Avatar with multiple decorations (badge + presence dot), card with multiple anchored controls (hover-to-edit + selection checkbox), data row with multiple action anchors, image with multiple annotation pins.