CSS propertyTransitions
transition-property
Specifies which CSS properties should change smoothly.
- Initial value
all- Inherited
- No
- Animatable
- no
- Applies to
- all elements and the ::before and ::after pseudo-elements
- JavaScript
element.style.transitionProperty = "opacity, transform"
Example
#CSS
.link {
transition-property: color, text-decoration-color;
transition-duration: 0.2s;
}Example HTML
<style>
.fade-link { color: #d4d4d4; text-decoration: underline; text-decoration-color: transparent; text-underline-offset: 4px; transition-property: color, text-decoration-color; transition-duration: .2s; }
.fade-link:hover { color: #fff; text-decoration-color: #a78bfa; }
</style>
<a class="fade-link" href="#">Hover over the link</a>Preview
Definition and usage
#The transition-property property takes a list of property names the transition applies to. All other changes happen immediately.
The all value animates everything that changes and can be animated. It is convenient, but it may accidentally animate things like height or border, which can be expensive and unexpected.
Not every property is animatable. For example, display changes abruptly by default, although transition-behavior: allow-discrete lets you include it in a transition.
Syntax
#Syntax
transition-property: none | all | <property-name> [, β¦]*;Values
#- Both position and colour change smoothly.
- Smooth movement, the colour changes abruptly.
- Smooth colour change, abrupt movement.
- No change is smooth.
Values in practice
#all
Both position and colour change smoothly.
.demo { transition-property: all; }transform
Smooth movement, the colour changes abruptly.
.demo { transition-property: transform; }background-color
Smooth colour change, abrupt movement.
.demo { transition-property: background-color; }none
No change is smooth.
.demo { transition-property: none; }Browser support
#Widely available
Works in all modern browsers, phones included. You can use it without worry.
- Chrome
- Edge
- Firefox
- Safari
Good practices
#- List only the properties that should really animate. Your transitions will be predictable.
- The order in the property list matches the order of the times in
transition-duration.
Related entries
#Practise it in lessons
#Spotted a mistake or missing an example? Write to us.