CSS animation-fill-mode Property

Beginner
⏱️ 6 min read
📚 Updated: Jun 2026
🎯 4 Examples
Animations & Timing

What You’ll Learn

The animation-fill-mode property decides what happens to an element’s styles before an animation starts and after it finishes. It helps you avoid elements snapping back to their original look too soon.

01

Before & After

Styles outside active time.

02

Syntax

Four keyword values.

03

none

Default reset behavior.

04

forwards

Keep final keyframe styles.

05

backwards

Apply first keyframe early.

06

both

Combine forwards and backwards.

Definition and Usage

The animation-fill-mode CSS property defines how computed values from an animation are applied to an element outside the active animation period — that is, before it begins and after it ends.

This is especially useful for entrance animations that should stay visible after finishing, or delayed animations that should already look like their starting keyframe while waiting to begin.

💡
Beginner Tip

If your animated element jumps back to its original position or opacity when the animation ends, try animation-fill-mode: forwards to keep the final keyframe styles.

📝 Syntax

Set animation-fill-mode with one of its keyword values:

syntax.css
selector {
  animation-fill-mode: none | forwards | backwards | both;
}

Basic Example

animation-fill-mode.css
.move {
  animation: moveRight 2s ease-out;
  animation-fill-mode: forwards;
}

Syntax Rules

  • The initial value is none, so styles outside the animation period are not preserved by default.
  • forwards keeps the styles from the last keyframe after the animation completes.
  • backwards applies the first keyframe styles during the delay before the animation starts.
  • both combines the behavior of forwards and backwards.
  • Fill mode can be included in the animation shorthand, usually after delay and iteration count.

⚡ Quick Reference

QuestionAnswer
Initial valuenone
Applies toElements with CSS animations
InheritedNo
AnimatableNo
Common useKeeping final animation styles after an entrance effect

Default Value

The initial value of animation-fill-mode is none. Outside the active animation period, the element does not retain keyframe styles from before or after the animation runs.

💎 Property Values

These keywords control style behavior before and after the animation plays.

ValueExampleMeaning
noneanimation-fill-mode: none;No keyframe styles apply before start or after end
forwardsanimation-fill-mode: forwards;Retains the final keyframe styles after the animation ends
backwardsanimation-fill-mode: backwards;Applies the first keyframe styles before the animation starts
bothanimation-fill-mode: both;Applies first keyframe styles before start and keeps final styles after end
initialanimation-fill-mode: initial;Resets to the default value none
inheritanimation-fill-mode: inherit;Inherits fill mode from the parent element
none

After the slide finishes, the box returns toward its original position instead of staying at the end.

Snaps back after end

Default behavior when fill mode is not set.

forwards

When the slide completes, the box stays at the final keyframe position on the right.

Keeps final styles

Click Restart above to replay and see the box stay at the end.

backwards

During the 1.2s delay, the box already uses the faded starting keyframe style before moving.

First keyframe during delay

Most visible when paired with animation-delay.

both

Uses the starting keyframe during the delay and keeps the final position after the animation ends.

Before delay + after end

Common choice for polished entrance animations.

When to Use Each Fill Mode

ValueBefore animationAfter animationBest for
noneNormal stylesNormal stylesLooping decorative motion
forwardsNormal stylesFinal keyframe stylesEntrance effects that should stay visible
backwardsFirst keyframe stylesNormal stylesDelayed starts that should look ready immediately
bothFirst keyframe stylesFinal keyframe stylesDelayed entrances that also hold the end state

👀 Live Preview

This box slides right over 2 seconds and stays there with animation-fill-mode: forwards:

Reload the page to see the animation again. The box remains at its final position instead of jumping back to the start.

Examples Gallery

Try animation-fill-mode with forwards, backwards, both, and shorthand syntax.

📚 Fill Mode Basics

Learn how fill mode changes what happens before and after an animation runs.

Example 1 — Keep the Final Position with forwards

Move a box across the screen and keep it at the end position after the animation completes.

animation-fill-mode-forwards.html
<style>
  @keyframes moveRight {
    from { left: 0; }
    to { left: 200px; }
  }
  .move {
    width: 100px;
    height: 100px;
    background: red;
    position: relative;
    animation: moveRight 2s ease-out;
    animation-fill-mode: forwards;
  }
</style>

<div class="move"></div>
Try It Yourself

How It Works

Without forwards, the box would return to left: 0 after the animation. With it, the final keyframe position remains.

Example 2 — Apply Starting Styles During a Delay

Use backwards so a fade-in element already looks like its first keyframe while waiting to animate.

animation-fill-mode-backwards.css
.banner {
  opacity: 1;
  animation: fadeUp 0.8s ease-out 1s;
  animation-fill-mode: backwards;
}
Try It Yourself

How It Works

During the 1 second delay, backwards applies the from keyframe styles so the banner starts invisible instead of flashing at full opacity.

Example 3 — Delayed Entrance That Stays Visible

Use both for a card that starts in its hidden keyframe state and remains visible after animating in.

animation-fill-mode-both.css
.card {
  animation: riseIn 0.9s ease-out 0.5s;
  animation-fill-mode: both;
}
Try It Yourself

How It Works

both applies the hidden starting styles during the delay and keeps the visible final styles after the animation finishes.

⚡ Shorthand Usage

Include fill mode directly in the animation shorthand for cleaner code.

Example 4 — Fill Mode in the Animation Shorthand

Add forwards at the end of the shorthand declaration.

animation-shorthand-fill.css
.toast {
  animation: slideIn 0.6s ease-out forwards;
}
Try It Yourself

How It Works

In animation: slideIn 0.6s ease-out forwards, the final keyword sets the fill mode so the toast stays on screen.

🧠 How animation-fill-mode Works

1

You define keyframes and timing

Set up start and end states, plus duration, delay, and iteration count.

Setup
2

You choose a fill mode

Decide whether first or last keyframe styles should apply outside the active animation window.

Fill mode
3

The browser applies styles before and after

backwards affects the delay period. forwards affects the time after completion.

Style retention
=

Polished animation results

Elements look intentional before, during, and after motion instead of snapping unexpectedly.

Universal Browser Support

animation-fill-mode is supported in all modern browsers alongside CSS animations.

Baseline · CSS Animations

Keep animation styles reliably in modern browsers

Chrome, Firefox, Safari, Edge, and Opera all support every animation-fill-mode keyword.

98% Modern browser support
Google Chrome43+ · Desktop & Mobile
Full support
Mozilla Firefox16+ · Desktop & Mobile
Full support
Apple Safari9+ · macOS & iOS
Full support
Microsoft Edge12+ · Modern versions
Full support
Opera30+ · Modern versions
Full support

Legacy browsers

Very old browsers without CSS animation support also lack animation-fill-mode.

💻
Internet Explorer IE 9 and earlier · No CSS animation support
None
animation-fill-mode property 98% supported

Bottom line: Use animation-fill-mode confidently for entrance effects and delayed animations in modern projects.

Conclusion

The animation-fill-mode property gives you control over styles before and after an animation runs. It is essential for polished entrance effects, delayed animations, and any motion that should not snap back when finished.

Reach for forwards when the final look should stay, backwards when the starting keyframe should appear during a delay, and both when you need both behaviors together.

💡 Best Practices

✅ Do

  • Use forwards for one-time entrance animations
  • Pair backwards with animation-delay to avoid pre-animation flashes
  • Use both for delayed cards, toasts, and modals
  • Test what happens after the animation ends in the UI
  • Respect prefers-reduced-motion for accessibility

❌ Don’t

  • Expect backwards to keep final styles after the animation
  • Use forwards on infinite looping animations unless intentional
  • Forget that default none may cause visible snapping
  • Confuse fill mode with animation direction or duration
  • Hide important content behind long delayed animations

Key Takeaways

Knowledge Unlocked

Five things to remember about animation-fill-mode

Use these points when styling before and after animations.

5
Core concepts
🔄02

none

Default reset behavior.

Default
▶️03

forwards

Keep final keyframe styles.

End state
04

backwards

Start keyframe during delay.

Pre-start
05

both

Combine both behaviors.

Complete

❓ Frequently Asked Questions

The animation-fill-mode property controls whether an element keeps animation styles before the animation starts, after it ends, or both.
The initial value is none, which means the element returns to its normal styles outside the active animation period.
forwards keeps the final keyframe styles after the animation ends. backwards applies the first keyframe styles before the animation starts, such as during a delay.
Use both when you want the starting keyframe styles during the delay and the ending keyframe styles to remain after the animation finishes.
Yes. Fill mode can be included in the animation shorthand, for example animation: fadeIn 1s ease-out forwards;

Practice in the Live Editor

Open the HTML editor, try animation-fill-mode: forwards, and see how the final styles stay applied.

HTML Editor →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

5 people found this page helpful