CSS

🎯 CSS animation Property

The animation property is a CSS shorthand property that allows you to define all animation settings in a single declaration. Instead of writing multiple animation-related properties separately, you can combine them into one concise line of code.

CSS animations make it possible to create engaging effects such as movement, fading, scaling, rotation, color changes, and many other visual transformations without using JavaScript.

πŸ”§ Animation Sub-Properties

The animation shorthand combines several individual CSS animation properties:

  • animation-name β†’ Defines which animation to run.
  • animation-duration β†’ Sets how long the animation lasts.
  • animation-timing-function β†’ Controls the animation speed curve.
  • animation-delay β†’ Specifies a delay before the animation starts.
  • animation-iteration-count β†’ Determines how many times the animation repeats.
  • animation-direction β†’ Defines the playback direction.
  • animation-fill-mode β†’ Controls element styles before and after the animation.
  • animation-play-state β†’ Specifies whether the animation is running or paused.

πŸ“Œ Default Values

The default values of the animation property are:

Default Values

animation:
none
0s
ease
0s
1
normal
none
running;
                

These defaults mean that no animation is applied unless you explicitly define one.

πŸ”Ή animation Values

1️⃣ animation value

Defines one or more animation settings in a single line.

CSS

.box {
    animation: slide 2s ease-in-out 0.5s infinite;
}
                

In this example:

  • slide β†’ Animation name
  • 2s β†’ Duration
  • ease-in-out β†’ Timing function
  • 0.5s β†’ Delay
  • infinite β†’ Repeat forever

2️⃣ initial

Resets the animation property and all its sub-properties to their default values.

CSS

.box {
    animation: initial;
}
                

πŸ§ͺ Practical Example

The following example creates a simple animation that moves an element horizontally.

CSS

.box {
    animation: moveBox 3s ease-in-out infinite;
}

@keyframes moveBox {
    from {
        transform: translateX(0);
    }

    to {
        transform: translateX(200px);
    }
}
                

The element continuously moves from left to right and repeats the animation forever.

πŸš€ Why Use animation?

The animation shorthand property simplifies animation management and keeps CSS code cleaner and easier to maintain.

  • Create advanced visual effects without JavaScript
  • Combine all animation settings in one line
  • Improve user engagement and interactivity
  • Build modern and dynamic web interfaces
  • Reduce repetitive CSS code
  • 🧠 Quick Summary

  • animation is a shorthand property for all CSS animation settings.
  • Controls animation name, duration, delay, timing function, direction, and repetition.
  • Helps create engaging and professional user interfaces.
  • Works together with @keyframes to create custom animations.