The Wayback Machine - https://web.archive.org/web/20240713091302/https://www.geeksforgeeks.org/css-transform-origin-property/
Open In App

CSS transform-origin Property

Last Updated : 04 Aug, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

The transform-origin property of CSS is used to specify the origin of the rotation of an element. It is the point at which an element is rotated. It can be used for both 2D and 3D rotations. 

Syntax:

transform-origin: position | initial | inherit

Property Values:

  • position: This specifies the position of the origin of rotation. It takes 3 values corresponding to the distance from the left edge of the box, the distance from the top edge of the box, and the z-axis of rotation. The values could be specified in length units, percentages or keywords. The z-axis value is always specified using length units. 
  • initial: This is used to set the property to its default value. 
  • inherit: This is used to inherit the property from its parent. 

Example 1: Specifying the position in length units 

html




<!DOCTYPE html>
<html>
   
<head>
    <style>
        .outer {
            margin: 50px;
            border: 1px dotted;
            position: relative;
            height: 100px;
            width: 400px;
            background-color: lightgreen;
        }
 
        .box {
            position: absolute;
            border: 1px solid;
            background: url(
 
            background-size: cover;
            height: 100px;
            width: 400px;
            transform: rotate(15deg);
            transform-origin: 10px 30px;
        }
    </style>
</head>
 
<body>
    <h1>CSS transform-origin Property</h1>
    <p>
      The CSS transform-origin Property is used to set
        the origin of the element's transformation
      </p>
    <div class="outer">
        <div class="box"></div>
    </div>
</body>
   
</html>


Output: values

 Example 2: Specifying the position in percentage 

html




<!DOCTYPE html>
<html>
   
<head>
    <style>
        .outer {
            margin: 50px;
            border: 1px dotted;
            position: relative;
            height: 100px;
            width: 400px;
            background-color: lightgreen;
        }
 
        .box {
            position: absolute;
            border: 1px solid;
            background: url(
 
            background-size: cover;
            height: 100px;
            width: 400px;
            transform: rotate(15deg);
            transform-origin: 50% 75%;
        }
    </style>
</head>
 
<body>
    <h1>CSS transform-origin Property</h1>
    <p>
      The CSS transform-origin Property is
        used to set the origin of the element's
        transformation
      </p>
    <div class="outer">
        <div class="box"></div>
    </div>
</body>
   
</html>


Output:

percentage

Example 3: Specifying the position in keywords 

html




<!DOCTYPE html>
<html>
   
<head>
    <style>
        .outer {
            margin: 50px;
            border: 1px dotted;
            position: relative;
            height: 100px;
            width: 400px;
            background-color: lightgreen;
        }
 
        .box {
            position: absolute;
            border: 1px solid;
            background: url(
 
            background-size: cover;
            height: 100px;
            width: 400px;
            transform: rotate(15deg);
            transform-origin: bottom left;
        }
    </style>
</head>
 
<body>
    <h1>CSS transform-origin Property</h1>
    <p>
      The CSS transform-origin Property is
        used to set the origin of the element's
        transformation
      </p>
    <div class="outer">
        <div class="box"></div>
    </div>
</body>
   
</html>


Output: keyword-value

Example: In this example, we are using transform-origin: initial property.

html




<!DOCTYPE html>
<html>
   
<head>
    <style>
        .outer {
            margin: 50px;
            border: 1px dotted;
            position: relative;
            height: 100px;
            width: 400px;
            background-color: lightgreen;
        }
 
        .box {
            position: absolute;
            border: 1px solid;
            background: url(
                ) no-repeat;
 
            background-size: cover;
            height: 100px;
            width: 400px;
            transform: rotate(15deg);
            transform-origin: initial;
        }
    </style>
</head>
 
<body>
    <h1>CSS transform-origin Property</h1>
    <p>
      The CSS transform-origin Property is
        used to set the origin of the element's
        transformation
      </p>
    <div class="outer">
        <div class="box"></div>
    </div>
</body>
   
</html>


Output: initial

Example: In this example, we are using the transform-origin: inherit property.

html




<!DOCTYPE html>
<html>
   
<head>
    <style>
        /* this acts as the parent */
         
        .outer {
            margin: 50px;
            border: 1px dotted;
            position: relative;
            height: 100px;
            width: 400px;
            background-color: lightgreen;
            /* set the property of the parent */
            transform-origin: bottom left;
        }
         
        .box {
            position: absolute;
            border: 1px solid;
            background: url(
            ) no-repeat;
         
            background-size: cover;
            height: 100px;
            width: 400px;
            transform: rotate(15deg);
            /* inherits the property of the parent */
            transform-origin: inherit;
        }
    </style>
</head>
 
<body>
    <h1>CSS transform-origin Property</h1>
    <p>
      The CSS transform-origin Property is used to set
    the origin of the element's transformation
      </p>
    <div class="outer">
        <div class="box"></div>
    </div>
</body>
   
</html>


Output: inherit

Supported Browsers: The browser supported by transform-origin property are listed below:

  • Chrome 36.0
  • Edge 12.0
  • Firefox 16.0
  • Safari 9.0
  • Opera 23.0


Similar Reads

Tailwind CSS Transform Origin
This class accepts lots of value in tailwind CSS in which all the properties are covered in class form. This class is used to specify the origin of the rotation of an element. It is the point about which an element is rotated. It can be used for both 2D and 3D rotations. In CSS, we can do that by using the CSS transform-origin property. Transform O
2 min read
Difference Between Git Push Origin and Git Push Origin Master
Understanding the difference between git push origin and git push origin master is important for efficient version control in Git. These commands are used to upload changes from your local repository to a remote repository, but they function differently. This article will explain these differences, how each command works, and when to use them. What
3 min read
Remote Add Origin vs Remote Set-Url Origin in Git
Git is an important tool for version control, allowing multiple developers to track and manage changes to code bases efficiently. Among its various functionalities, the commands remote add origin and remote set-url origin play important roles in managing remote repositories. This article will explore each command, their uses, features, and key diff
3 min read
CSS perspective-origin Property
The perspective-origin property in CSS is used to define the position at which the user is looking 3D object i.e. the vanishing point of the 3D object. Syntax: perspective-origin: x-axis y-axis|initial|inherit; Property Values: x-axis: It represents the horizontal position of the perspective origin. The possible value of x-axis are listed below:per
2 min read
CSS background-origin property
The background-origin property in CSS is your key to managing the background image of a webpage. It sets the origin point of the image in the background, with the default setting placing the background image origin at the upper-left corner of the screen/webpage. Syntax:  background-origin: padding-box|border-box|content-box|initial|inherit;Property
4 min read
CSS mask-origin property
The CSS mask-origin property determines the positioning reference of a CSS mask image applied to an element using mask-image. It defines where the mask image originates within the element's box model, influencing how the mask is positioned and clipped. Syntax: mask-origin: Keyword values /* Or */ mask-origin: Multiple values /* Or */ mask-origin: N
2 min read
CSS transform-style Property
The transform-style property is used to specify the children of an element are positioned in 3D space or flattened with respect to the plane of the element. Syntax: transform-style: flat|preserve-3d|initial|inherit; Property Values: flat: This value places the child elements in the same plane as the parent. It does not preserve the 3D position. It
3 min read
How to apply multiple transform property to an element using CSS ?
There is a variety of procedures to apply multiple transform property in an element. In this article we will discuss the easiest and popular ones. In the 1st method we will be combining the transform property itself. In the 2nd method, we will use the nested classes to apply other transforms. Method 1: In this method, we will combine the transform
3 min read
What is the purpose of the transform Property in CSS ?
The transform Property in CSS is used to apply various graphical transformations to HTML elements. It allows developers to modify the appearance and layout of elements by altering their position, rotation, scale, and skew. The primary purposes of the transform property include: Positional AdjustmentsMove elements in the 2D or 3D space, shifting the
1 min read
CSS transform Property
The transform property in CSS is used to change the coordinate space of the visual formatting model. This is used to add effects like skew, rotate, translate, etc on elements. Try It: .custom-item { border: 1px solid gray; font-family: "Gill Sans", "Gill Sans MT", Calibri, "Trebuchet MS", sans-serif; border-radius: 3px; margin: auto; margin-top: 5p
9 min read
three90RightbarBannerImg