# animation-fill-mode

> The `animation-fill-mode` CSS property specifies how an element should be styled before and after an animation is executed.

## How do I keep the final state after a CSS animation ends?

The property that determines what styles are applied to the element before and after the animation runs. It can make the element keep its animation styles after the animation ends or reset to its original state.

- Topic: Animations
- Type: property
- Browser support: Chrome 43+, Chrome Android 43+, Edge 12+, Firefox 16+, Firefox Android 16+, Safari 9+, Safari iOS 9+

## Example

Wrong:

```css
.notice {
  animation: fade-out 0.5s;
}
@keyframes fade-out {
  to { opacity: 0; }
}
```

Right:

```css
.notice {
  animation: fade-out 0.5s forwards;
}
@keyframes fade-out {
  to { opacity: 0; }
}
```

With 'forwards', the element keeps the last keyframe instead of popping back to full opacity.

## Common mistakes

- The element jumps back to its original style when the animation ends.
- Hover styles stop working because a 'forwards' animation still overrides the property.

## Key points

- Entry animations with a delay use 'backwards' or 'both', so the first keyframe applies during the delay.
- 'forwards' isn't used for state that other styles must change later, since the filled value overrides them.

## Interview questions

### What is the difference between forwards, backwards and both?

'forwards' keeps the last keyframe after the end, 'backwards' applies the first keyframe during the delay, and 'both' does both.

### Why can't I change a property after a forwards animation?

The filled animation value still overrides normal styles. Remove the animation, or set the final value in the base styles instead.

## Related cards

- [animation](https://wonderium.dev/css/animation.md)
- [animation-delay](https://wonderium.dev/css/animation-delay.md)
- [@keyframes](https://wonderium.dev/css/keyframes.md)
- [animation-range](https://wonderium.dev/css/animation-range.md)

---

- Level: [CSS](https://wonderium.dev/css.md)
- HTML version: https://wonderium.dev/css/animation-fill-mode
- Last updated: 2026-11-25
