π¬ CSS COURSE β MODULE 12: TRANSITIONS & ANIMATIONS
π File: animations.md
π¬ CSS Animations & Transitions
π Introduction
Animations in CSS help you:
- improve user experience
- add smooth interactions
- make UI feel modern and dynamic
π There are 2 main types:
- Transitions (simple effects)
- Animations (advanced keyframes)
β‘ 1. Transitions (SMOOTH CHANGES)
π Basic Transition
button {
transition: 0.3s;
}
β Makes changes smooth
π― Hover Effect Example
button {
background: blue;
transition: 0.3s;
}
button:hover {
background: red;
}
β Smooth color change on hover
β±οΈ 2. Transition Properties
div {
transition: all 0.5s ease;
}
Parts:
allβ apply to all properties0.5sβ durationeaseβ timing function
π Timing Functions
| Value | Effect |
|---|---|
| ease | smooth start/end |
| linear | constant speed |
| ease-in | slow start |
| ease-out | slow end |
π 3. Transform (MOVEMENT)
div:hover {
transform: scale(1.1);
}
Common transforms:
transform: translateX(20px);
transform: rotate(10deg);
transform: scale(1.2);
π¬ 4. CSS Animations (KEYFRAMES)
π Basic Structure
@keyframes move {
from {
transform: translateX(0);
}
to {
transform: translateX(100px);
}
}
βΆοΈ Apply Animation
div {
animation: move 2s;
}
π 5. Advanced Keyframes
@keyframes bounce {
0% {
transform: translateY(0);
}
50% {
transform: translateY(-50px);
}
100% {
transform: translateY(0);
}
}
div {
animation: bounce 1s infinite;
}
β Infinite looping animation
π§ 6. Animation Properties
animation: name duration timing delay iteration;
Example:
animation: bounce 2s ease-in-out 0s infinite;
π¨ 7. Real UI Example
<button>Hover Me</button>
button {
padding: 10px 20px;
background: blue;
color: white;
border: none;
transition: 0.3s;
}
button:hover {
transform: scale(1.1);
background: darkblue;
}
β οΈ Common Mistakes
- Overusing animations β
- Too fast animations β
- Using animations everywhere β
- Ignoring performance β
π― Best Practice
π Use animation for:
- buttons
- loading states
- hover effects
- small UI feedback
β Donβt animate everything
π§ͺ Mini Exercise
Create:
- A button that scales on hover
- A box that moves left-right
- A bouncing element using keyframes
- A smooth color transition card