CSS transform-origin Property

Description

The transform-origin CSS property specifies the point around which a CSS transformation, such as rotation, scaling, or skewing, is applied to an element. It determines the pivot point for these transformations, influencing both the position and direction of the transformation. By default, the transformation origin is set to the center of the element, but you can customize it using values like percentages, pixels, or keywords like "top," "bottom," "left," and "right." This property is essential for controlling how an element behaves when animated or transformed, allowing developers to create visually appealing and precise effects on web elements.

Initial value
50% 50%
Applies to
Transformable elements
Inherited
No
Computed value
For <length> the absolute value, otherwise a percentage
Animatable
Yes
JavaScript syntax
object.style.transformOrigin

Interactive Demo

Hover over me

Syntax

transform-origin: [ left | center | right | top | bottom | <percentage> | <length> ]
 | 
   [ left | center | right | <percentage> | <length> ]
  [ top | center | bottom | <percentage> | <length> ] <length>?
 |
   [ center | [ left | right ] ] && [ center | [ top | bottom ] ] <length>?

Values

  • <percentage>A percentage for the horizontal offset is relative to the width of the bounding box. A percentage for the vertical offset is relative to height of the bounding box. The value for the horizontal and vertical offset represent an offset from the top left corner of the bounding box.
  • <length>A length value gives a fixed length as the offset. The value for the horizontal and vertical offset represent an offset from the top left corner of the bounding box.
  • topComputes to '0%' for the vertical position.
  • rightComputes to '100%' for the horizontal position.
  • bottomComputes to '100%' for the vertical position.
  • leftComputes to '0%' for the horizontal position.
  • centerComputes to '50%' ('left 50%') for the horizontal position if the horizontal position is not otherwise specified, or '50%' ('top 50%') for the vertical position if it is.

Example

<h2>Example of using the transform-origin property in CSS</h2> 
<div class="static"><div class="test" > 50% 50% 0 </div></div>
<div class="static"><div class="test2" > left top </div></div>
<div class="static"><div class="test3"> center bottom </div></div>
<br>
<div class="static"><div class="test4"> 100% 0% </div></div>
<div class="static"><div class="test5"> 50% 50% 250px </div></div>
<div class="static"><div class="test6"> 50% top -250px </div></div>
.static {
   margin: 10px;
   background: gray;
   display: inline-block; 
} 
div {
   width: 180px; 
   height: 100px; 
   line-height: 100px;
   text-align: center; 
} 
.test, .test3, .test5 { 
   background: plum;  
} 
.test2, .test4, .test6 { 
   background: orange;  
}
@ -webkit-keyframes iliketomoveit {
   100% { 
      -moz-transform: rotate(2turn);
      -webkit-transform: rotate(2turn);
      -ms-transform: rotate(2turn);
      transform: rotate(2turn);
   } 
} 
@keyframes iliketomoveit { 
   100% { 
      -moz-transform: rotate(2turn);
      -webkit-transform: rotate(2turn);
      -ms-transform: rotate(2turn);
      transform: rotate(2turn);
   } 
}
.test:hover {
   -webkit-animation: iliketomoveit 2s linear infinite; 
   animation: iliketomoveit 2s linear infinite;
   transform-origin: 50% 50% 0; 
   -webkit-transform-origin: 50% 50% 0; 
   -moz-transform-origin: 50% 50% 0; 
   -ms-transform-origin: 50% 50% 0; 
}  
.test2:hover { 
   -webkit-animation: iliketomoveit 2s linear infinite;
   animation: iliketomoveit 2s linear infinite; 
   transform-origin: left top; 
   -webkit-transform-origin : left top; 
   -moz-transform-origin: left top; 
   -ms-transform-origin: left top; 
} 
.test3:hover { 
   -webkit-animation: iliketomoveit 2s linear infinite; 
   animation: iliketomoveit 2s linear infinite; 
   transform-origin: center bottom; 
   -webkit-transform-origin: center bottom; 
   -moz-transform-origin: center bottom; 
   -ms-transform-origin: center bottom; 
}  
.test4:hover { 
   -webkit-animation: iliketomoveit 2s linear infinite; 
   animation: iliketomoveit 2s linear infinite; 
   transform-origin: 100% 0%;
   -webkit-transform-origin: 100% 0%;
   -moz-transform-origin: 100% 0%;
   -ms-transform-origin: 100% 0%;
}  
.test5 {
    -webkit-animation: iliketomoveit 5s ease-out infinite; 
    animation: iliketomoveit 5s ease-out infinite; 
    transform-origin: 50% 50% 250px;
   -webkit-transform-origin: 50% 50% 250px; 
   -moz-transform-origin: 50% 50% 250px; 
   -ms-transform-origin: 50% 50% 250px;
   transform: scale3d(0.5, -1, 2); 
   -webkit-transform: scale3d(0.5, -1, 2); 
   -moz-transform: scale3d(0.5, -1, 2); 
   -ms-transform: scale3d(0.5, -1, 2); 
}  
.test6 {
   -webkit-animation: iliketomoveit 5s ease-out infinite; 
   animation: iliketomoveit 5s ease-out infinite;
   transform-origin: 50% top -250px; 
   -webkit-transform-origin: 50% top -250px;
   -moz-transform-origin: 50% top -250px; 
   -ms-transform-origin: 50% top -250px;
   transform: scale3d(0.5, -1, 2); 
   -webkit-transform: scale3d(0.5, -1, 2); 
   -moz-transform: scale3d(0.5, -1, 2);
   -ms-transform: scale3d(0.5, -1, 2); 
}  

Browser Support

The following table will show you the current browser support for the CSS transform-origin property.

Desktop
Edge Chrome Firefox Opera Safari
123616239
Tablets / Mobile
Chrome Firefox Opera Safari Samsung Webview
361624934.4

Last updated by CSSPortal on: 2nd January 2024