Write CSS to create a pulsing animation
Description: Create a circle that grows and shrinks again and again.
Hint:
- Define the steps with
@keyframes. - Attach it with
animation: name duration timing infinite.
CSS pulsing animation
<style>
@keyframes pulse {
0% { transform: scale(1); }
50% { transform: scale(1.3); }
100% { transform: scale(1); }
}
.dot {
width: 50px;
height: 50px;
border-radius: 50%;
background: #e91e63;
animation: pulse 1.2s ease-in-out infinite;
}
</style>
<div class="dot"></div>
Output in the browser:
Output in the browser
How it works
- The result is a pink circle. On your page it grows to 1.3 times its size at 50% of the time and then returns to normal. This does not move in this box.
infiniterepeats the animation forever.transformis smooth and cheap for the browser to animate.
Read CSS Transitions and Animations.
Learn more about the similar topics:
| Tutorials |
|---|
| CSS Shadows |
| CSS Opacity / Transparency |
| CSS Transitions and Animations |
| Exercises & Assignments |
|---|
| Write CSS to create a card with box shadow and gradient background |
| Write CSS to create a pulsing animation |
| Interview Questions & Answers |
|---|
| What is the difference between CSS transition and animation? |