CSS animations

فهرست فصل‌ها دانلود آرشیوناشر

MDN Web Docs · نسخهٔ df622a2a1c1e · CC BY-SA 2.5 و مجوز جداگانهٔ ناشر برای نمونه‌کد

The CSS animations module lets you animate the values of CSS properties, such as background-position and transform, over time by using keyframes. Each keyframe describes how the animated element should render at a given time during the animation sequence. You can use the properties in the animations module to control the duration, number of repetitions, delayed start, and other aspects of an animation.

Animations in action

To view the animation in the box below, click the checkbox 'Play the animation' or hover the cursor over the box. When the animation is active, the cloud at the top changes shape, snowflakes fall, and the snow level at the bottom rises. To pause the animation, uncheck the checkbox or move your cursor away from the box.

html hidden live-sample___animation
css hidden live-sample___animation

{{EmbedLiveSample("animation", "", "610px")}}

This sample animation uses {{cssxref("animation-iteration-count")}} to make the flakes fall repeatedly, {{cssxref("animation-direction")}} to make the cloud move back and forth, {{cssxref("animation-fill-mode")}} to raise the snow level in response to the cloud movement, and {{cssxref("animation-play-state")}} to pause the animation.

Click "Play" in the example above to see or edit the code for the animation in the MDN Playground.

Reference

Properties

  • {{cssxref("animation")}} shorthand
  • {{cssxref("animation-composition")}}
  • {{cssxref("animation-delay")}}
  • {{cssxref("animation-direction")}}
  • {{cssxref("animation-duration")}}
  • {{cssxref("animation-fill-mode")}}
  • {{cssxref("animation-iteration-count")}}
  • {{cssxref("animation-name")}}
  • {{cssxref("animation-play-state")}}
  • {{cssxref("animation-timeline")}}
  • {{cssxref("animation-timing-function")}}

At-rules and descriptors

  • {{cssxref("@keyframes")}}
  • [<keyframe-selector>](/en-US/docs/Web/CSS/Reference/Selectors/Keyframe_selectors)

Events

All animations, even those with 0 seconds duration, throw animation events.

  • {{domxref("Element/animationstart_event", "animationstart")}}
  • {{domxref("Element/animationend_event", "animationend")}}
  • {{domxref("Element/animationcancel_event", "animationcancel")}}
  • {{domxref("Element/animationiteration_event", "animationiteration")}}

Interfaces

  • Web Animations API
  • {{domxref("AnimationEvent")}}
  • {{domxref("CSSAnimation")}}
  • {{domxref("CSSKeyframeRule")}}
  • {{domxref("CSSKeyframesRule")}}

Guides

  • Using CSS animations
  • : Step-by-step tutorial on how to create animations using CSS. This article describes the animation-related CSS properties and at-rule and how they interact with each other.
  • Animatable CSS properties
  • : Overview of how different CSS properties can be animated, including their animation types and interpolation methods.
  • Using the Web Animations API
  • : Common animation requirements that can be solved with a few lines of JavaScript.

Related concepts

  • CSS animation triggers module
  • {{cssxref("animation-trigger")}}
  • {{cssxref("timeline-trigger")}} shorthand
  • {{cssxref("timeline-trigger-activation-range")}} shorthand
  • {{cssxref("timeline-trigger-activation-range-end")}}
  • {{cssxref("timeline-trigger-activation-range-start")}}
  • {{cssxref("timeline-trigger-active-range")}} shorthand
  • {{cssxref("timeline-trigger-active-range-end")}}
  • {{cssxref("timeline-trigger-active-range-start")}}
  • {{cssxref("timeline-trigger-name")}}
  • {{cssxref("timeline-trigger-source")}}
  • {{cssxref("trigger-scope")}}
  • CSS scroll-driven animations module
  • {{cssxref("animation-range")}} shorthand
  • {{cssxref("animation-range-end")}}
  • {{cssxref("animation-range-start")}}
  • {{cssxref("scroll-timeline")}} shorthand
  • {{cssxref("scroll-timeline-axis")}}
  • {{cssxref("scroll-timeline-name")}}
  • {{cssxref("timeline-scope")}}
  • {{cssxref("view-timeline")}} shorthand
  • {{cssxref("view-timeline-axis")}}
  • {{cssxref("view-timeline-inset")}}
  • {{cssxref("view-timeline-name")}}
  • {{cssxref("will-change")}} CSS property
  • {{cssxref("easing-function")}} data type
  • [prefers-reduced-motion](/en-US/docs/Web/CSS/Reference/At-rules/@media/prefers-reduced-motion) media query
  • {{glossary("Bezier curve")}} glossary term

Specifications

{{Specifications}}

See also

  • CSS scroll-driven animations module
  • CSS animation triggers module
  • CSS transitions module
  • The {{cssxref("interpolate-size")}} property and {{cssxref("calc-size()")}} function for enabling animations to and from intrinsic size values.
  • The {{htmlelement("canvas")}} HTML element along with canvas API and WebGL API to draw graphics and animations.
  • The {{domxref("SVGAnimationElement")}} interface for all the animation-related element interfaces, including {{domxref("SVGAnimateElement")}}, {{domxref("SVGSetElement")}}, {{domxref("SVGAnimateMotionElement")}}, and {{domxref("SVGAnimateTransformElement")}}.