Yogesh Chauhan's Blog

transform-origin Property in CSS

in CSS on February 16, 2021

transform-origin property to me is like hanging the object on a point and then using that point as a center to move the object.

The transform-origin property let us change the position of elements with transform property set.

If we have elements with 2D transformations set then we can pin the transform-origin point to move those elements in x- and y-axis. We can also do that for z-axis if we have 3D transformations set for an element.

transform-origin property has a default values of 50% 50% 0

That value is always set unless we define something else to be set.

As we can see that by default it pins the elements in the center of the element so when we ONLY specify the transform property, it will adjust according to that default pin set.

And if we move that pin using transform-origin property then it will use that new pin point to adjust the elements on x or y or z axis depending on the transform-origin property value.

All major browsers support it so feel free to use it.


transform-origin: x-axis y-axis z-axis|initial|inherit;

x-axis and y-axis possible values are left, center, right, length and % but for z-axis only one possible value is length.


transform-origin: center

transform-origin: top left

transform-origin: 25% 25%

transform-origin: top left, transform: skewX(50deg)

Source: w3.org

Most Read

#1 How to check if radio button is checked or not using JavaScript? #2 Solution to “TypeError: ‘x’ is not iterable” in Angular 9 #3 How to add Read More Read Less Button using JavaScript? #4 How to uninstall Cocoapods from the Mac OS? #5 PHP Login System using PDO Part 1: Create User Registration Page #6 How to Use SQL MAX() Function with Dates?

Recently Posted

#Aug 15 Is PHP still good for back-end programming? #Aug 10 How to create a multisite network in WordPress? #Aug 3 How to create a circle that follows a cursor using JavaScript and CSS? #Aug 3 How to make a curtain slider using jQuery and CSS? #Aug 2 How to progressively load images and add a blurry placeholder? #Aug 1 How to create a placeholder loader (throbber) using CSS?
You might also like these
WordPress 5.7 is migrating to latest jQuery version and people are freaking outjQueryHow to create a simple drop down menu using JavaScript and CSS?CSSWhat’s a Closure in JavaScript?JavaScriptCreate a responsive image gallery using CSS gridCSSHow to create a simple digital clock using JavaScript?JavaScriptHow to add menu to your WordPress theme?WordPress