Frontend Masters Blog · 5 min readCSS & layout
Elastic/Stretching UI With CSS Anchors
CSS anchors let elements stretch dynamically between points, enabling elastic UI effects like toggle indicators and navigation highlights. By assigning anchor names to selected items and using inset with anchor() values, the indicator expands and contracts with timed transitions, creating smooth, direction‑aware animations.
- Use anchor-name on the selected element and inset:anchor() on the indicator to bind dimensions
- Apply transition delays to opposite sides for a stretch‑then‑shrink animation
- Combine JavaScript class toggling with CSS min() and keyframe animations for multi‑option navigation