Re: [csswg-drafts] [web-animations-2] Element.animate could allow keyframes to come from CSS declaration (#2070)

My main concern with the string version is that it sounds nice and simple (`new Animation('spin')` or something), but there's a lot of magic that goes underneath and things that need to be right for that to do the right thing from an imperative API.

First you need to define _when_ the name lookup happens. The most straight-forward way would be to define the name lookup to be synchronous. In that case:

 * The style sheet that defines the animation might not be loaded yet.
 * It will force the engine to do a synchronous "process the active stylesheet list", and lookup the name _somehow_ (which with shadow dom is not so trivial). I guess we could define the lookup similar to how the style attribute works.

If you define the name lookup to be async, then lots of questions arise, like:
 * When exactly is it looked up?
 * Does it cause _other_ parts of the API to do this synchronous lookup? E.g. if you ask for the animation effect?
 * What happens if the thing that the name refers to changes mid animation or between you call this and the environment changes (e.g. media queries). With CSS that might trigger a new animation, but the original one persists (or gets cancelled? But still, it sticks around in the old form if you hang on to it from script).

I think only the "async name lookup" version technically would have a problem with media queries (or similar things). But making the API work or not depending on stylesheet load timing or what not feels rather unfortunate...

-- 
GitHub Notification of comment by emilio
Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/2070#issuecomment-3941512114 using your GitHub account


-- 
Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config

Received on Sunday, 22 February 2026 18:44:29 UTC