CSS properties for creating animations and smooth transitions
Main CSS Properties for Animations and Transitions
CSS provides two approaches for creating visual effects:
- Smooth transitions (
transition) β for simple effects (on hover, focus, etc.) - Animations (
@keyframes + animation) β for complex and multi-step effects
Transition β Smooth Transitions
Used for animating property changes when element state changes.
css
.button {
background: blue;
transition: background 0.3s ease;
}
.button:hover {
background: red;
}Main Properties:
transition-propertyβ which property to animatetransition-durationβ durationtransition-timing-functionβ easing functiontransition-delayβ delay before start
Animation β Complex Animations
For multi-step animations with full control.
css
@keyframes slideIn {
from {
transform: translateX(-100%);
}
to {
transform: translateX(0);
}
}
.element {
animation: slideIn 1s ease-out;
}Main Properties:
animation-nameβ keyframes nameanimation-durationβ durationanimation-timing-functionβ easinganimation-delayβ delayanimation-iteration-countβ repeat countanimation-directionβ direction
Tip:
Use transition for simple effects, animation for complex multi-step animations.
Short Answer
Interview readyPremium
A concise answer to help you respond confidently on this topic during an interview.