transform-origin
Sets the point an element rotates around and scales from.
- Initial value
50% 50% 0- Inherited
- No
- Animatable
- yes, as a length or percentage
- Applies to
- transformable elements
- JavaScript
element.style.transformOrigin = "top left"
Example
#.progress-bar {
transform: scaleX(0.7);
transform-origin: left;
}<div style="height: 10px; border-radius: 99px; background: #262626; overflow: hidden;">
<div class="progress-bar" style="height: 100%; background: linear-gradient(90deg, #7c3aed, #0ea5e9); transform: scaleX(0.7); transform-origin: left;"></div>
</div>
<p style="margin: 8px 0 0; color: #a3a3a3;">70% of the module completed</p>Definition and usage
#The transform-origin property sets the centre of a transform. By default it is the centre of the element, so rotation spins the element around its centre and scaling enlarges it evenly in all directions.
Moving the point to a corner completely changes the effect: rotating around the top left corner works like a door opening on a hinge, and scaling from the bottom makes the element grow upwards.
It accepts keywords (top, left, centerβ¦), percentages, and lengths. The third value sets the offset along the Z axis for 3D transforms.
Syntax
#transform-origin: <x> <y>? <z>?;Values
#- Rotation around the centre of the element.
- Rotation around the top left corner.
- Rotation around the bottom right corner.
outside the element
The pivot point is below the element, like a pendulum.
Values in practice
#center
.demo { transform-origin: center; }top left
.demo { transform-origin: top left; }bottom right
.demo { transform-origin: bottom right; }50% 150%
.demo { transform-origin: 50% 150%; }Browser support
#Widely available
Works in all modern browsers, phones included. You can use it without worry.
- Chrome
- Edge
- Firefox
- Safari
Good practices
#- Progress bars animated with
scaleX()needtransform-origin: left, otherwise they grow from the centre. - Dropdown menus look more natural when they scale from the point they emerge from, for example
top right.
Related entries
#- transformMoves, rotates, scales, or skews an element without affecting the page layout.
- rotateRotates an element by a given angle, independently of the transform property.
- scaleEnlarges or shrinks an element, independently of the transform property.
- perspective-originSets the point from which the viewer looks at a 3D scene.
Practise it in lessons
#Spotted a mistake or missing an example? Write to us.