css · level 3 · unit 6 · lesson 1
- meet it
- guess first
- your turn
- fix it
- nailed it
Tap a green word if you get lost.
meet it
lists the stops, and an element plays them.
A transition needs a change, like hover, before it starts. An plays by itself, from the moment the page loads. You describe it once with @keyframes and a name, then attach that name to any element.
Inside, each is a stop in time: from is the start, to is the end, and percentages like 50% sit in between. Each stop holds the styles for that moment, and the browser draws every frame between them.
Attach it with animation-name: pulse and animation-duration: 2s. With no duration, the animation lasts zero seconds and you see nothing.
<span class="live">Live</span> @keyframes pulse {
from { opacity: 1; }
50% { opacity: 0.3; }
to { opacity: 1; }
}
.live {
font-weight: bold;
color: crimson;
animation-name: pulse;
animation-duration: 2s;
} Press show my page to see it here.
It plays once when the page loads, so press run again to replay it; two lessons from now it will repeat.
guess first
The name is attached but there is no duration. What happens?
Guess before you run it. Wrong guesses are how you learn, and nothing is marked.
<div class="toast">Saved</div> @keyframes slide-in {
from { translate: 0 20px; }
to { translate: 0 0; }
}
.toast {
padding: 12px;
background-color: #e0f2f1;
animation-name: slide-in;
}
your turn
Your turn. Make the heart beat.
Fill in the blanks: attach the beat keyframes to the heart and make one beat last 0.8 seconds.
the page you’re styling
<span class="heart">♥</span>your css
Press show my page to see it here.
- the heart plays
beatnot checked yet - one beat lasts 0.8 secondsnot checked yet
fix it
The loading bar never fills. Can you fix it?
the page you’re styling
<div class="bar"></div>your css
Press show my page to see it here.
- the bar plays the
fillkeyframesnot checked yet - the fill takes 3 secondsnot checked yet
- The duration is fine. Are there keyframes with the exact name the bar asks for?
- The keyframes are called
fill, but the bar asks forfill-bar. - Change the
animation-namevalue tofill, then press run.
nailed it
you made the page move on its own. :D
@keyframes namelists the stops, fromfromtoto.animation-namemust match the keyframes exactly.- No
animation-durationmeans0s, so nothing shows.
new words in your collection
- animation
- @keyframes
- keyframe
This lesson isn’t saved. A free account remembers every lesson you finish.