CSS Transitions & Animations
Transitions and animations make a webpage feel smooth, interactive and premium. In this chapter, you will learn hover effects, transform, keyframes and animation properties.
transition
Smoothly changes CSS property values.
transform
Moves, scales, rotates or skews elements.
@keyframes
Defines steps of an animation.
animation
Runs repeated or timed motion effects.
After This Chapter, You Will Understand
This chapter teaches smooth and professional motion effects for webpages.
Transitions
Create smooth changes on hover and focus.
Transform
Move, scale and rotate webpage elements.
Keyframes
Define animation steps from start to end.
Animation
Run automatic motion effects on elements.
Why Use Transitions and Animations?
Motion effects make interactions smoother and help guide user attention.
1 Simple Meaning
A transition creates a smooth change between two states, such as normal button and hover button. An animation runs through a sequence of styles using keyframes.
2 Common Uses
- Button hover effects
- Card lift effects
- Menu opening effects
- Loading indicators
- Attention-grabbing badges
- Hero section movement
transition Property
The transition property makes style changes smooth instead of sudden.
3 Basic Syntax
background: #06285f;
transition: all 0.3s ease;
}
.button:hover {
background: #ff7a1a;
}
Hover the Button
The button changes color, moves up and gets a shadow smoothly.
| Transition Part | Meaning | Example |
|---|---|---|
| Property | Which CSS property should animate | background, transform, all |
| Duration | How long the transition takes | 0.3s, 500ms |
| Timing Function | Speed style of transition | ease, linear, ease-in-out |
| Delay | Wait time before transition starts | 0.2s |
Move, Scale and Rotate Elements
The transform property changes the shape or position of an element visually.
translate()
scale()
rotate()
@keyframes Rule
Keyframes define the steps of an animation from start to end.
4 Keyframes Syntax
0% {
transform: translateY(0);
}
50% {
transform: translateY(-20px);
}
100% {
transform: translateY(0);
}
}
Floating Animation
This animation moves the element up and down repeatedly.
Animation Properties
Animation properties connect an element with keyframes and control timing.
| Property | Use | Example |
|---|---|---|
| animation-name | Name of keyframes | floatBox |
| animation-duration | How long one animation cycle takes | 2s |
| animation-timing-function | Speed style | ease-in-out |
| animation-iteration-count | How many times animation runs | infinite, 3 |
| animation-direction | Direction of animation | normal, alternate |
Float
Pulse
Slide
Practice Transitions and Animations
Edit transition, transform and animation values to see the effect.
Mistakes Students Should Avoid
Animations should make the user experience better, not confusing or heavy.
Wrong Habits
- Adding too many animations on one page
- Using very fast or distracting movement
- Animating layout-heavy properties unnecessarily
- Forgetting transition duration
- Using hover-only effects for important information
Correct Habits
- Use subtle motion for premium feel
- Prefer transform and opacity for smooth effects
- Keep duration comfortable
- Use animations to guide attention
- Keep website speed and accessibility in mind
Test Your Understanding
Select the correct answers and check your score.
1. Which property creates smooth change between styles?
2. Which property can scale, rotate or move an element?
3. Which rule defines animation steps?
4. Which animation value makes animation repeat forever?
5. Which properties are usually smoother to animate?
Remember These Points
Revise these before moving to Chapter 23.
Transition
Smoothly changes CSS values between two states.
Hover Effect
Applies style when user points over an element.
Transform
Moves, scales, rotates or skews elements.
Keyframes
Defines animation steps from start to end.
Animation
Runs motion effects using keyframes.
Best Practice
Use subtle motion and avoid distracting animations.