CSS transform-origin
Published Jul 30, 2021Updated Oct 31, 2022
Contribute to Docs
The transform-origin property sets the origin of an element’s transformation.
Syntax
transform-origin: <values>;
The transform-origin property can have up to three values:
- The first value is for the x-axis:
leftcenterright- Length value (e.g.,
50px) - Percentage value (e.g.,
25%)
- The second value is for the y-axis:
topcenterbottom- Length value (e.g.,
50px) - Percentage value (e.g.,
25%)
- The third value is for the z-axis and can only be a length value (e.g.,
50px).
Note: The order in which the x-axis and y-axis values are declared does not matter if only keywords are used.
Example 1
Setting an img elements transformation origin from the center.
img {transform-origin: center;}
Example 2
Setting an img elements transformation origin from the top left.
img {transform-origin: top left;}
Example 3
Setting an img elements transformation origin from the bottom left with a z-axis offset of 100px.
img {transform-origin: bottom left 100px;}
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn CSS on Codecademy
- Front-end engineers work closely with designers to make websites beautiful, functional, and fast.
- Includes 34 Courses
- With Professional Certification
- Beginner Friendly.115 hours
- A full-stack engineer can get a project done from start to finish, back-end to front-end.
- Includes 51 Courses
- With Professional Certification
- Beginner Friendly.150 hours