Favorites

HTML onanimationend Event Attribute

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
onanimationend
HTML Event AttributeThis event attribute is supported by all modern browsers.
Updated 22nd November 2026

Description

The onanimationend event attribute runs a script when a CSS animation finishes all of its iterations. It does not fire if the animation is removed before it ends (that fires animationcancel), and it never fires for animations with animation-iteration-count: infinite. It is often used to remove a class or element after an exit animation.

The event is an AnimationEvent with the properties animationName (the name of the @keyframes rule), elapsedTime (in seconds, not counting animation-delay) and pseudoElement (for example "::before"). Animation events bubble, so one handler on a parent can watch all of its children; check event.target to see which element is animating.

Syntax

<element onanimationend="script">

Values

  • scriptThe name of the script to use when the event has been triggered.

Example

<!DOCTYPE html>
<html>
<head>
<title>onanimationend event</title>
<style>
#box {
width: 60px;
height: 60px;
background: #4361ee;
}
#box.run {
animation: move 1s ease-in-out 3 alternate;
}
@keyframes move {
to { transform: translateX(200px); }
}
</style>
</head>
<body>
<button onclick="var b = document.getElementById('box'); b.classList.remove('run'); void b.offsetWidth; b.classList.add('run')">Start animation</button>
<button onclick="document.getElementById('box').classList.remove('run')">Stop</button>
<div id="box" onanimationstart="log('animationstart: ' + event.animationName)" onanimationiteration="log('animationiteration')" onanimationend="log('animationend after ' + event.elapsedTime + 's')" onanimationcancel="log('animationcancel')"></div>
<ul id="log"></ul>
<script>
function log(text) {
var li = document.createElement("li");
li.textContent = text;
document.getElementById("log").appendChild(li);
}
</script>
</body>
</html>
Open in editor

Browser Support

The following information will show you the current browser support for the HTML onanimationend event attribute. Hover over a browser icon to see the version that first introduced support for this HTML event attribute.

This event attribute is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee