i've been experimenting with building an animated focus ring using CSS anchor positioning https://codepen.io/hi_mayank/pen/MWNrBpQ

i'm adding a pseudo-element on the body itself, so it requires no extra HTML. and unlike a regular outline, it won't get clipped by adjacent elements or overflow.

issues:
- it does not work for elements focused inside a popover or dialog.
- i'm also trying to animate it but it's not performant bc you cannot use anchored values in transforms.

Anchored focus ring

...

@mayank Ooo, I'm intrigued by this idea. I wonder if there's a way to clip the focus ring when scrolling. `position-visibility: anchors-visible;` will hide it if the anchor scrolls out of bounds, but it's not clipped.

https://codepen.io/jamessw/pen/zYgpLQX

Anchored focus ring

...

@Jamessw @mayank tbh, I find the “fully visible when not entirely hidden” a better behavior when being clipped, as it makes it much easier to spot the focus ring. Otherwise, could be probably done with scroll-driven animations, though likely not in a very clean manner.