Animation Direction Fill-Mode and Iteration
Control animation playback direction, how many times it loops, and the final state with fill-mode.
Animation Direction Fill-Mode and Iteration is a free CSS Academy lesson on CoddyKit. This is lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the CSS Academy learning path, and your progress syncs across the web and the CoddyKit app. The CSS Academy course includes 4 lessons in total.
animation-iteration-count
Controls how many times the animation repeats. Use infinite for continuous looping.
<div class="spinner"></div>
<div class="pulse"></div>
animation-direction
Controls the playback direction on alternate cycles:
normal— plays forward each iterationreverse— plays backwardalternate— forward then backward, alternatingalternate-reverse— backward then forward
<div class="bounce"></div>
animation-fill-mode
Defines what happens to the element before the animation starts and after it ends:
none— default, reverts to original stateforwards— holds the last keyframe after completionbackwards— applies first keyframe during delayboth— applies both backwards and forwards
forwards Fill Mode
The most common use case — keep the element in its animated final state after the animation completes:
<p class="item">I fade in and stay visible</p>
backwards Fill Mode
When there is a delay, backwards makes the element start at the first keyframe state during the delay period, preventing a flash of the original state before animation starts:
<p class="item">Starts invisible during the delay</p>
both Fill Mode
both combines forwards and backwards — the most predictable option for animated elements that should not flash before or after the animation.
animation-delay
Delays the start of an animation. Negative delays make the animation start mid-way through — useful for synchronizing multiple animations:
<div class="item">Item 1</div>
<div class="item">Item 2</div>
<div class="item">Item 3</div>
Staggered Animation Pattern
CSS-only stagger using nth-child delays:
<div class="item">Item 1</div>
<div class="item">Item 2</div>
<div class="item">Item 3</div>
<div class="item">Item 4</div>
Pausing and Resuming
Toggle the animation state with JavaScript by changing animation-play-state:
<div class="spinner" id="js-spinner"></div>
<button onclick="const s=document.getElementById('js-spinner').style; s.animationPlayState = s.animationPlayState === 'paused' ? 'running' : 'paused';">Pause / Resume</button>
Resetting Animations
To replay a CSS animation, remove and re-add the class. The browser applies a trick: force a reflow between removal and addition.
<div class="box" id="reset-box"></div>
<button onclick="const el=document.getElementById('reset-box'); el.classList.remove('animate'); void el.offsetWidth; el.classList.add('animate');">Replay Animation</button>
Negative animation-delay
Start an animation mid-playback using a negative delay — useful for synchronized background patterns or looping elements that should appear already in motion.
<div class="star"></div>
<div class="star"></div>
<div class="star"></div>
Quick Check
Which animation-fill-mode value keeps the element at its final keyframe state after the animation ends?
Recap
animation-iteration-count: infinite loops forever. animation-direction: alternate yo-yos. animation-fill-mode: forwards holds the final state. animation-fill-mode: both is the safest option. Use negative delays to offset synchronized animations.
Learn CSS with an AI tutor — free
Write and run real code in your browser, get instant help from a 24/7 AI tutor, and pick up where you left off on the web or in the app.
- Courses
- 40
- Lessons
- 159
Frequently Asked Questions
Is the “Animation Direction Fill-Mode and Iteration” lesson free?
Yes — the full text of “Animation Direction Fill-Mode and Iteration” is free to read here on the web. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the CSS Academy course, upgrade to CoddyKit PRO. The CSS Academy course includes 4 lessons in total.
What will I learn in “Animation Direction Fill-Mode and Iteration”?
Control animation playback direction, how many times it loops, and the final state with fill-mode. You practise CSS Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start CSS Academy?
No prior experience is required. CSS Academy on CoddyKit is structured for beginners through advanced learners, so you can start here or from the beginning and move at your own pace. This is lesson 2 of 4.
How long does the “Animation Direction Fill-Mode and Iteration” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this CSS Academy lesson?
Yes. Every CSS Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- @keyframes Syntax and Animation Property
- Animation Direction Fill-Mode and Iteration
- Chaining and Sequencing Animations
- Accessible Animations with prefers-reduced-motion