api-member
Element.animate — CSS reference
Creates and plays a Web Animation; it returns the Animation for pausing, seeking or cancellation. Respect reduced-motion preferences in real interfaces.
Formal Syntax & Structure
css syntaxcss
element.animate(keyframes, options)Working Example
Example Snippetcss
<!doctype html><html lang="en"><meta charset="utf-8"><title>Element.animate</title><style>body{margin:0;font:16px system-ui}#a{box-sizing:content-box;width:120px;height:60px;padding:8px;border:3px solid #475569;overflow:auto}#output{white-space:pre-wrap}
</style><body><div id="a">Example</div><pre id="output" aria-live="polite"></pre><script>const a=document.getElementById("a"); window.demoResult=(async()=>{const anim=a.animate([{opacity:0},{opacity:1}],{duration:2000,fill:"both"});anim.pause();await anim.ready;anim.currentTime=1500;return Number(getComputedStyle(a).opacity);})();window.demoResult.then(v=>document.getElementById("output").textContent=JSON.stringify(v),e=>document.getElementById("output").textContent=String(e));</script></body></html>