9+
The badge is positioned to the top-right of the button.
If you searched css anchor positioning or how to position a tooltip in CSS, the anchor APIs tether one element to another without JavaScript coordinates. Learn anchor-name, position-anchor, and position-area with a fallback.
Tether a badge to a button with anchor-name.
The badge is positioned to the top-right of the button.
.btn { anchor-name: --btn; }
.badge {
position: absolute;
position-anchor: --btn;
position-area: top right;
}Show a tooltip below an anchor with no JS coordinates.
position-area: bottom places the tooltip under the button.
.tip {
position: absolute;
position-anchor: --btn;
position-area: bottom;
margin-top: 0.5rem;
}Keep a usable layout where anchors are unsupported.
Gate anchor rules with @supports and keep a static fallback.
@supports (anchor-name: --x) {
.badge { position-anchor: --btn; position-area: top right; }
}