Menu
×
   ❮     
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS DSA TYPESCRIPT ANGULAR ANGULARJS GIT POSTGRESQL MONGODB ASP AI R GO KOTLIN SWIFT SASS VUE GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE INTRO TO PROGRAMMING INTRO TO HTML & CSS BASH RUST

HTML and CSS Animations


Animations

CSS animations run keyframe sequences directly in the browser, ideal for micro-interactions, loading indicators, and storytelling without heavy JavaScript.


Keyframe syntax

  • Define an animation with @keyframes name { ... }.
  • Specify property values at percentages (0%, 50%, 100%) or keywords (from/to).
  • Apply the animation to elements with animation-name, animation-duration, and related properties.

Note: Keyframes are snapshots of styles at certain times.

The browser fills in the frames between them automatically.

If you want to read more about CSS Animations or get an in-depth understanding, go to CSS Animations in our CSS tutorial.


Animation properties

  • animation-duration, animation-delay control timing.
  • animation-timing-function sets easing between keyframes.
  • animation-iteration-count defines loop count or infinite.
  • animation-direction (normal, reverse, alternate).
  • animation-fill-mode determines styles before/after animation.

Note: animation-fill-mode: forwards keeps the final style after the animation finishes; backwards applies the first keyframe before it starts.

Use animation shorthand to set multiple values at once.



Example: Loading Pulse

This example defines a simple pulse using @keyframes and applies it to a dot.

The animation alternates between two states using the alternate direction.

Keyframes in action

<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="styles.css" type="text/css">
</head>
<body>
  <div class="loader"></div>
</body>
</html>
.loader {
  width: 16px;
  height: 16px;
  border-radius: 999px;
  background: #2563eb;
  animation: pulse 900ms ease-in-out infinite alternate;
}
@keyframes pulse {
  from { transform: scale(0.75); opacity: 0.6; }
  to   { transform: scale(1.4); opacity: 1; }
}
Try it Yourself »

The from/to keyframes scale and fade the dot.

The infinite alternate setting loops the animation back and forth smoothly.


Sequencing

  • Use delays or staggered start times for list reveal animations.
  • Combine multiple animations using comma-separated values.
  • Paired elements can share keyframes with different durations or delays.

Accessibility considerations

  • Respect @media (prefers-reduced-motion: reduce): disable or simplify animations.
  • Avoid large parallax or flashing effects that cause motion sickness.
  • Provide user controls for complex animated sequences.

Note: Always give users a way to pause long or looping animations so they do not become distracting.



×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
sales@w3schools.com

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
help@w3schools.com

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookies and privacy policy.

Copyright 1999-2025 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.