π Introduction
The transition-property CSS property specifies **which CSS properties should animate** when a transition occurs. It works together with:
transition-duration, transition-timing-function, andtransition-delay. By defining transition-property correctly, you can create smooth, polished UI animations. π¨β¨
π― What Does transition-property Do?
- Specifies which CSS properties will animate
- Allows choosing one or multiple properties
- Helps optimize animations by avoiding unnecessary transitions
- Works with hover, focus, active, JS-triggered states
β¨ Syntax
Syntax
selector {
transition-property: none | all | <property-name> | <property-name>, <property-name>;
}Note
π§© Available Values
1. all
Default value β animates **every property** that changes. Simple, but not always efficient.
Code Snippet
transition-property: all;2. none
Disables transitions completely.
Code Snippet
transition-property: none;3. Single Property
Animates only the specified property.
Code Snippet
transition-property: opacity;4. Multiple Properties
Separate properties with commas.
Code Snippet
transition-property: background-color, transform, opacity;π₯ Practical Examples
1. Fade on Hover
Fade Effect
.fade {
transition-property: opacity;
transition-duration: 0.3s;
}
.fade:hover {
opacity: 0.5;
}2. Smooth Color Change
Color Transition
.btn {
transition-property: background-color;
transition-duration: 0.4s;
}
.btn:hover {
background-color: #4f46e5;
}3. Multiple Transitions Together
Multi-property
.box {
transition-property: transform, opacity;
transition-duration: 0.4s;
}
.box:hover {
transform: scale(1.1);
opacity: 0.8;
}4. Transition Only Width
Width Example
.expand {
transition-property: width;
transition-duration: 0.5s;
}
.expand:hover {
width: 300px;
}5. Prevent Certain Properties From Animating
Prevent Animation
.card {
transition-property: box-shadow;
transition-duration: 0.3s;
}
.card:hover {
box-shadow: 0 6px 20px rgba(0,0,0,0.15);
background-color: #fff; /* won't animate! */
}π Commonly Animated Properties
| Property | Why Animate? |
|---|---|
| opacity | Easy fade effects |
| background-color | Smooth color transitions |
| transform | Scaling, rotation, moving |
| width / height | Expandable sections |
| box-shadow | Soft hover depth |
π§ Tips & Best Practices
- Only animate the properties you need β improves performance.
- Use transform & opacity for the smoothest animations.
- Avoid animating layout properties (height, width, top, left) unless necessary.
- Combine transitions with
:hover,:focus, or JavaScript events.
π Conclusion
The transition-property property lets you precisely define which CSS properties should animate during state changes. Itβs an essential part of building smooth hover effects, UI animations, and interactive components. Master it along with transition-duration,transition-timing-function, and transition-delay to create beautiful, polished transitions in your CSS. π