What are the key differences between CSS transformations and transitions?
Both of those are used to change current shape/state of an object. (you can do pretty animations with JS etc..)
But it's still not clear for me which one to use where and for what.
Transformation is a fundamental change of state, the passage from one way of being to another. Transition is a gradual psychological and emotional process through which individuals and groups reorient themselves so that they can function and find meaning in a changed situation.
linear - specifies a transition effect with the same speed from start to end. ease-in - specifies a transition effect with a slow start. ease-out - specifies a transition effect with a slow end. ease-in-out - specifies a transition effect with a slow start and end.
The transform CSS property lets you rotate, scale, skew, or translate an element. It modifies the coordinate space of the CSS visual formatting model.
With CSS3 we can specify how an element changes by just describing its current and target states. CSS3 will create a smooth transition between these states by applying a cubic Bézier curve and gradually change the element appearance.
transition
and transform
are separate CSS properties, but you can supply transform
to transition
to "animate" a transformation.transition
The CSS transition
property listens for changes to specified properties (background-color, width, height, etc.) over time.
transition
Property Syntax:
selector { transtion: [property-name] [duration] [timing-function] [delay] }
For example, the below styles will change the color of a div's background to orange over a period of 1 second upon hover.
div { width: 100px; height: 100px; background-color: yellow; transition: background-color 1s; /* timing function and delay not specified */ } div:hover { background-color: orange; }
<div></div>
transform
The CSS transform
property rotates/scales/skews an element over the X,Y, or Z axes. Its behavior does not relate to transition
. Simply put, on page load, the element will just appear rotated/skewed/scaled.
Now if you wanted the rotating/skewing/scaling to happen, say when a user hovered over the element, you would need to "transition" the "transformation".
Here's how: since the transition
property's functionality is to listen to changes in other css properties, you can actually supply transform
as an argument to transition
and "animate" the transformation based on desired trigger (for example, a hover action).
transform
Property Syntax
select { transform: [rotate] [skew] [scale] [translate] [perspective] }
For example, the below styles will rotate a div over a period of 1 second upon hover.
div { width: 100px; height: 100px; background-color: yellow; transition: transform 1s; /* timing function and delay not specified */ } div:hover { transform: rotate(30deg); }
<div></div>
They're completely different things.
Transitions:
CSS Transitions allows property changes in CSS values to occur smoothly over a specified duration.
Transforms:
CSS transforms allows elements styled with CSS to be transformed in two-dimensional or three-dimensional space.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With