css · level 3 · unit 6 · lesson 3
- meet it
- guess first
- your turn
- fix it
- nailed it
Tap a green word if you get lost.
meet it
The animation shorthand sets every part in one line.
Real code rarely spells out every animation- property. The shorthand does it in one line: animation: pulse 2s ease-in-out 0.5s infinite alternate both;. The order is free, with one rule: the first time is the duration and the second is the delay.
infinite is the count, how many play-throughs to run. Each iteration goes from the first keyframe to the last. alternate plays every other iteration backwards, so it never snaps back to the start.
The both keeps the first keyframe's styles during the delay and the last keyframe's styles after the end, so nothing flickers.
<div class="toast">Message sent</div> @keyframes rise {
from { opacity: 0; translate: 0 12px; }
to { opacity: 1; translate: 0 0; }
}
.toast {
padding: 12px 16px;
color: white;
background-color: #264653;
animation: rise 0.4s ease-out 1s both;
} Press show my page to see it here.
guess first
Two times in one shorthand. Which one is the delay?
Guess before you run it. Wrong guesses are how you learn, and nothing is marked.
<p class="hint">Tap to start</p> @keyframes nudge {
to { translate: 6px 0; }
}
.hint {
animation: nudge 0.3s 2s 3 alternate;
}
your turn
Your turn. Write a glow in one line.
Fill in the shorthand so glow lasts 1.5 seconds, waits 0.5 seconds before starting, repeats forever and plays back and forth.
the page you’re styling
<button class="cta">Join the beta</button>your css
Press show my page to see it here.
- one glow lasts 1.5 secondsnot checked yet
- it waits 0.5 seconds firstnot checked yet
- it repeats forevernot checked yet
- it plays back and forthnot checked yet
fix it
The banner flashes before it fades in. Can you fix it?
the page you’re styling
<div class="banner">Free delivery this week</div>your css
Press show my page to see it here.
- the first keyframe holds during the delaynot checked yet
- the banner still waits a secondnot checked yet
- For the first second the banner shows at full strength. Then the animation starts at
opacity: 0. - A fill mode can hold the first keyframe's styles during the delay.
- Add
bothto the end of the shorthand, then press run.
nailed it
you packed a whole animation into one line. :D
- In the shorthand, the first time is the duration, the second the delay.
infiniterepeats andalternateplays every other iteration backwards.bothholds the first and last keyframes' styles.
new words in your collection
- iteration
- fill mode
This lesson isn’t saved. A free account remembers every lesson you finish.