The @keyframes at-rule defines the steps of a CSS animation. Give it a name, describe how styles change over time, then apply it with the animation property.
01
Keyframes
Define steps.
02
from / to
Start & end.
03
0% – 100%
Timeline.
04
animation
Apply it.
05
transform
Move & scale.
06
At-rule
Not property.
Fundamentals
Introduction
The @keyframes at-rule in CSS defines how an animation progresses over time. Each keyframe is a snapshot of styles at a specific moment on the timeline. The browser smoothly interpolates between those snapshots to create motion and visual change.
Definition and Usage
@keyframes is not a CSS property — it is an at-rule, like @media or @font-face. It only defines an animation. To run it, you must apply the animation property (or its longhand parts like animation-name and animation-duration) on an element.
The name you give your @keyframes block must match the animation-name you use on the element. For example, @keyframes fadeIn pairs with animation: fadeIn 1s;.
💡
Beginner Tip
Think of @keyframes as a recipe and animation as the instruction to cook it. The recipe lists steps; the animation property tells the browser when to start, how long to run, and whether to repeat.
Foundation
📝 Syntax
The simplest form uses from and to for the start and end states:
syntax-from-to.css
@keyframesfadeIn{from{opacity:0;}to{opacity:1;}}
Use percentage values when you need steps in between:
aria-hidden on decorative motion — Purely visual animations should not confuse screen readers.
🧠 How @keyframes Works
1
@keyframes defines steps
You name the animation and set styles at from, to, or percentage points.
Define
2
animation property triggers it
An element with animation: name duration starts the timeline.
Trigger
3
Browser interpolates
Styles blend smoothly between keyframes based on the timing function.
Interpolate
=
🎨
Animated element
The element moves, fades, or changes over the defined duration.
Compatibility
🖥 Browser Compatibility
The @keyframes at-rule and CSS animations have universal support in all modern browsers including Chrome, Firefox, Safari, Edge, and Opera.
✓ Baseline · Universal support
@keyframes + CSS animations
Keyframe animations work in every major browser without vendor prefixes in current versions.
100%@keyframes rule
Google ChromeAll modern versions
Full support
Mozilla FirefoxAll modern versions
Full support
Apple SafariAll modern versions
Full support
Microsoft EdgeAll modern versions
Full support
OperaAll modern versions
Full support
@keyframes at-rule100% supported
Bottom line:@keyframes is safe for production. Pair with prefers-reduced-motion for accessible animations.
Wrap Up
🎉 Conclusion
The @keyframes at-rule lets you build rich CSS animations by defining style changes at specific timeline points. Combine it with the animation property to control duration, timing, repetition, and fill behavior.
Start with simple from/to animations, add percentage steps when needed, and prefer transform and opacity for smooth performance. Always consider users who prefer reduced motion.
The @keyframes at-rule defines the steps of a CSS animation. You give it a name and describe how styles change at different points in time — then connect that name to an element using the animation property.
First define @keyframes myAnim { ... }, then apply it: animation: myAnim 2s ease-in-out infinite;. The animation-name must match the @keyframes name exactly.
from is the same as 0% (start) and to is the same as 100% (end). Use percentages when you need intermediate steps like 25%, 50%, or 75% along the timeline.
Properties that can change smoothly over time work best: opacity, transform, color, background-color, width, height, and more. Avoid animating layout-heavy properties like margin when transform performs better.
Yes. @keyframes and CSS animations are supported in all modern browsers including Chrome, Firefox, Safari, Edge, and Opera. Always respect prefers-reduced-motion for accessibility.