Retour au cours

Lesson 95: Introduction to CSS Keyframe Animations

**La Maîtrise de CSS : De zéro à expert en 100 leçons** *(Alternative, slightly punchier version using a common French idiomatic structure for full coverage: CSS : Maîtrisez l'essentiel en 100 leçons, but the first option is closer to the original progression.)*

95. Introduction to CSS Keyframe Animations

While transitions handle changes between two states (e.g., normal to hover), CSS animations allow for complex, multi-step sequences of style changes over time.

Step 1: Defining Keyframes (@keyframes)

You first define the name and the steps of the animation using the @keyframes rule. Steps are defined by percentages (0% to 100%) or keywords (from and to).

css @keyframes pulse { /* Start state / 0% { transform: scale(1); opacity: 1; } / Mid-state / 50% { transform: scale(1.05); opacity: 0.8; } / End state */ 100% { transform: scale(1); opacity: 1; } }

Step 2: Applying the Animation

You apply the animation to an element using the animation property (shorthand) or its longhand properties.

css .pulsing-box { /* 1. Name 2. Duration 3. Timing Function 4. Iteration Count */ animation: pulse 2s ease-in-out infinite; }