Performance: Transition property
This affects the smoothness and speed of visual changes on the page, impacting user interaction responsiveness and visual stability.
Jump into concepts and practice - no test required
button {
transition: background-color 0.3s ease;
}
button:hover {
background-color: red;
}button {
transition: all 0.3s ease;
}
button:hover {
width: 200px;
background-color: red;
}| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Transition on 'all' including width | Multiple style recalculations | Multiple reflows per frame | High paint cost | [X] Bad |
| Transition on 'background-color' only | Minimal style recalculations | No reflows | Low paint cost | [OK] Good |
| Transition on 'transform' property | Minimal style recalculations | No reflows | GPU accelerated paint | [OK] Good |
| Transition on 'height' property | Triggers layout recalculation | Reflow per frame | High paint cost | [X] Bad |
transition property do?transitiontransition property is used to animate changes in CSS properties smoothly instead of instantly.background-color property lasting 0.5 seconds?transition: property duration; so property name comes first, then duration.button {
background-color: blue;
transition: background-color 1s;
}
button:hover {
background-color: red;
}
What will happen when the user moves the mouse over the button?background-color lasting 1 second, so changes to this property animate smoothly..box {
width: 100px;
transition: 2s width;
}
.box:hover {
width: 200px;
}transition: property duration;. Here, duration comes before property, which is wrong.color and background-color on a button hover, but only color changes smoothly. Which CSS fixes this?