CSS transform-origin Property
The CSS transform-origin property specifies the point around which an element's CSS transformations are applied.
By default, most HTML elements rotate and scale around their center. Changing transform-origin allows transformations to occur around an edge, corner, custom position, or a point in three-dimensional space. It works with the transform property and the individual rotate and scale properties.
transform-origin Syntax
The transform-origin property accepts one, two, or three values that define the horizontal, vertical, and optional depth coordinates of the transformation origin.
Basic Syntax
.example {
transform-origin: center;
}
One-Value Syntax
.example {
transform-origin: left;
}
.example {
transform-origin: top;
}
.example {
transform-origin: 25%;
}
.example {
transform-origin: 20px;
}
A single horizontal keyword, length, or percentage sets the horizontal position and defaults the vertical position to center. A single top or bottom keyword sets the vertical position and defaults the horizontal position to center.
Two-Value Syntax
.example {
transform-origin: left top;
}
.example {
transform-origin: right bottom;
}
.example {
transform-origin: 25% 75%;
}
.example {
transform-origin: 30px 20px;
}
.example {
transform-origin: center bottom;
}
Two values identify the horizontal and vertical coordinates. When both are keywords, their order may be interchangeable if one identifies a horizontal position and the other a vertical position.
Three-Value Syntax
.example {
transform-origin: center center 50px;
}
.example {
transform-origin: left top 20px;
}
.example {
transform-origin: 25% 75% -30px;
}
The third value specifies the Z-axis position and must be a length. Percentages are not allowed for the third value.
CSS-Wide Keywords
.example {
transform-origin: initial;
}
.example {
transform-origin: inherit;
}
.example {
transform-origin: unset;
}
.example {
transform-origin: revert;
}
.example {
transform-origin: revert-layer;
}
Invalid Examples
.example {
transform-origin: left right;
}
.example {
transform-origin: top bottom;
}
.example {
transform-origin: center center 50%;
}
.example {
transform-origin: 20px, 30px;
}
Two horizontal or two vertical keywords cannot form a valid pair. The Z-axis coordinate cannot be a percentage, and position values must be separated by spaces rather than commas.
Property Values
| Value | Description |
|---|---|
left |
Positions the horizontal origin at the left edge of the reference box. |
center |
Positions the origin at the center of the applicable axis. |
right |
Positions the horizontal origin at the right edge of the reference box. |
top |
Positions the vertical origin at the top edge of the reference box. |
bottom |
Positions the vertical origin at the bottom edge of the reference box. |
<percentage> |
Positions the origin relative to the width or height of the reference box. |
<length> |
Positions the origin at a specified distance from the reference box's starting edge. |
| Third length value | Specifies the Z-axis position for three-dimensional transformations. |
Property Characteristics
| Characteristic | Value |
|---|---|
| Initial value | 50% 50% 0 |
| Inherited | No |
| Applies to | Transformable elements |
| Computed value | Lengths made absolute; percentages retained |
| Animation type | Simple list of length, percentage, or calculated values |
| Percentages | Relative to the selected transformation reference box |
| Negative values | Allowed for lengths and percentages |
| Specification | CSS Transforms Module Level 1 and Level 2 |
Note: The initial value for most HTML elements is 50% 50% 0. Some SVG elements without an associated CSS layout box have an initial transformation origin of 0 0 instead.
How It Works
The transform-origin property determines the point around which transformations are calculated. It does not move or rotate an element by itself.
Step 1: Create an Element
<div class="transform-box">Rotate Me</div>
Step 2: Define Its Appearance
.transform-box {
width: 150px;
height: 80px;
background: #dbeafe;
border: 2px solid #2563eb;
}
Step 3: Apply a Rotation
.transform-box {
transform: rotate(30deg);
}
Without an explicit origin, the element rotates around its center.
Step 4: Change the Origin
.transform-box {
transform-origin: top left;
transform: rotate(30deg);
}
The element now rotates around its top-left corner.
Step 5: Use a Custom Position
.transform-box {
transform-origin: 25% 75%;
transform: rotate(30deg);
}
The origin is positioned 25% across the reference box and 75% down from its top edge.
Understanding the Pivot Point
When an element rotates or scales, the transformation origin acts as its pivot point. Changing that point changes the visual result without changing the element's original layout position.
Keyword Values
Keyword values provide convenient positions along the edges and center of the transformation reference box.
Center
.example {
transform-origin: center;
transform: rotate(30deg);
}
Rotates the element around its center.
Top Left
.example {
transform-origin: top left;
transform: rotate(30deg);
}
Rotates the element around its top-left corner.
Top Right
.example {
transform-origin: top right;
transform: rotate(30deg);
}
Bottom Left
.example {
transform-origin: bottom left;
transform: rotate(30deg);
}
Bottom Right
.example {
transform-origin: bottom right;
transform: rotate(30deg);
}
Left Center
.example {
transform-origin: left center;
transform: rotate(30deg);
}
Right Center
.example {
transform-origin: right center;
transform: rotate(30deg);
}
Center Top
.example {
transform-origin: center top;
transform: rotate(30deg);
}
Center Bottom
.example {
transform-origin: center bottom;
transform: rotate(30deg);
}
Equivalent Keyword Order
.first {
transform-origin: left top;
}
.second {
transform-origin: top left;
}
Both declarations select the top-left corner.
Percentage Values
Percentage values position the transformation origin relative to the dimensions of the selected reference box.
Center Origin
.example {
transform-origin: 50% 50%;
}
This is equivalent to center center.
Top-Left Origin
.example {
transform-origin: 0% 0%;
}
Bottom-Right Origin
.example {
transform-origin: 100% 100%;
}
Custom Percentage Position
.example {
transform-origin: 25% 75%;
}
The horizontal origin is 25% of the reference box's width from the left edge. The vertical origin is 75% of its height from the top edge.
Percentage and Keyword Combination
.example {
transform-origin: 30% bottom;
}
Negative Percentages
.example {
transform-origin: -20% 50%;
transform: rotate(30deg);
}
The origin is positioned outside the left edge of the reference box.
Percentages Greater Than 100%
.example {
transform-origin: 120% 50%;
transform: rotate(30deg);
}
The origin is positioned beyond the right edge of the reference box.
Responsive Behavior
Percentage origins automatically adjust when the reference box changes size, making them useful for responsive elements.
Length Values
Length values position the transformation origin using CSS units such as pixels, rems, and ems.
Pixel Values
.example {
transform-origin: 30px 20px;
}
The origin is positioned 30 pixels from the left edge and 20 pixels from the top edge of the reference box.
Using rem Units
.example {
transform-origin: 2rem 1rem;
}
Using em Units
.example {
transform-origin: 2em 1em;
}
Combining Lengths and Percentages
.example {
transform-origin: 30px 50%;
}
Negative Lengths
.example {
transform-origin: -20px 50%;
transform: rotate(30deg);
}
The origin is positioned 20 pixels outside the left edge of the reference box.
Using calc()
.example {
transform-origin: calc(50% + 20px) center;
}
The horizontal origin is positioned 20 pixels to the right of the reference box's center.
When to Use Length Values
Use lengths when the pivot point must be positioned at a specific distance rather than a proportional position.
3D Transform Origin
Three-dimensional transformations can use a third transform-origin value to position the origin along the Z axis.
Basic 3D Origin
.example {
transform-origin: center center 50px;
transform: perspective(600px) rotateY(45deg);
}
Positive Z Position
.example {
transform-origin: 50% 50% 80px;
transform: perspective(600px) rotateX(30deg);
}
A positive Z value moves the transformation origin toward the viewer in the element's local coordinate system.
Negative Z Position
.example {
transform-origin: 50% 50% -80px;
transform: perspective(600px) rotateY(30deg);
}
A negative Z value positions the origin farther away along the Z axis.
Corner-Based 3D Origin
.example {
transform-origin: left top 40px;
transform: perspective(600px) rotateY(45deg);
}
Invalid Z Percentage
.example {
transform-origin: center center 50%;
}
The third value must be a length. Percentages are not valid for the Z-axis coordinate.
When to Use a 3D Origin
Use a Z-axis origin when creating 3D rotations, hinged panels, layered interfaces, or perspective-based effects.
Rotation and transform-origin
The transformation origin is particularly noticeable when an element rotates.
Rotate Around the Center
.example {
transform-origin: center;
transform: rotate(30deg);
}
Rotate Around the Top-Left Corner
.example {
transform-origin: top left;
transform: rotate(30deg);
}
Rotate Around the Bottom-Right Corner
.example {
transform-origin: bottom right;
transform: rotate(30deg);
}
Rotate Around an External Point
.example {
transform-origin: -30px 50%;
transform: rotate(30deg);
}
The element rotates around a point outside its left edge, creating a wider circular movement.
Animated Rotation
.rotating-element {
transform-origin: left center;
animation: swing 2s ease-in-out infinite alternate;
}
@keyframes swing {
from {
transform: rotate(-15deg);
}
to {
transform: rotate(15deg);
}
}
Using the Individual rotate Property
.example {
transform-origin: top left;
rotate: 30deg;
}
The individual rotate property also uses the specified transformation origin.
Scaling and transform-origin
Scaling enlarges or reduces an element relative to its transformation origin.
Scale From the Center
.example {
transform-origin: center;
transform: scale(1.5);
}
Scale From the Top-Left Corner
.example {
transform-origin: top left;
transform: scale(1.5);
}
Scale From the Bottom Edge
.example {
transform-origin: center bottom;
transform: scaleY(1.5);
}
Scale From the Right Edge
.example {
transform-origin: right center;
transform: scaleX(1.5);
}
Hover Scaling
.card {
transform-origin: center;
transition: transform 0.3s ease;
}
.card:hover {
transform: scale(1.05);
}
Using the Individual scale Property
.example {
transform-origin: top left;
scale: 1.2;
}
The individual scale property uses the same transformation origin.
Important Consideration
Scaling changes the element's rendered size but does not change the space it occupies in normal document flow.
Translation and transform-origin
Pure translation moves an element without rotating or scaling it. Changing the transformation origin does not change the visual result of a translation alone.
Translation With the Default Origin
.example {
transform-origin: center;
transform: translateX(40px);
}
Translation With a Different Origin
.example {
transform-origin: top left;
transform: translateX(40px);
}
Both examples move the element 40 pixels horizontally.
Combining Translation and Rotation
.example {
transform-origin: top left;
transform: translateX(40px) rotate(30deg);
}
When rotation is included, the origin affects the rotational part of the combined transformation.
Combining Translation and Scaling
.example {
transform-origin: left center;
transform: translateX(20px) scale(1.2);
}
Important Distinction
The transform-origin property controls the pivot point of transformations. It does not replace translation or positioning properties.
Working With transform-box
The transform-box property selects the reference box used to calculate the transformation origin.
Border Box Reference
.example {
transform-box: border-box;
transform-origin: center;
transform: rotate(30deg);
}
Content Box Reference
.example {
transform-box: content-box;
transform-origin: center;
transform: rotate(30deg);
}
SVG Fill Box Reference
svg .shape {
transform-box: fill-box;
transform-origin: center;
transform: rotate(30deg);
}
SVG View Box Reference
svg .shape {
transform-box: view-box;
transform-origin: center;
transform: rotate(30deg);
}
Why the Reference Box Matters
A percentage-based origin is calculated relative to the selected reference box. Changing that box can change the location of the origin even when the transform-origin declaration stays the same.
Important Distinction
transform-origin selects the pivot point, while transform-box selects the box used to calculate that point.
Using transform-origin With SVG
SVG graphics may use a different default transformation origin from ordinary HTML elements. Explicitly setting transform-box and transform-origin provides more predictable control.
SVG Example
<svg viewBox="0 0 300 200" xmlns="http://www.w3.org/2000/svg">
<rect class="svg-shape" x="50" y="60" width="100" height="70" fill="#93c5fd" />
</svg>
Rotate Around the Shape Center
.svg-shape {
transform-box: fill-box;
transform-origin: center;
transform: rotate(30deg);
}
Rotate Around the SVG Viewport Center
.svg-shape {
transform-box: view-box;
transform-origin: center;
transform: rotate(30deg);
}
Rotate Around a Shape Corner
.svg-shape {
transform-box: fill-box;
transform-origin: top left;
transform: rotate(30deg);
}
Using the Stroke Bounding Box
.svg-shape {
stroke: #2563eb;
stroke-width: 10;
transform-box: stroke-box;
transform-origin: center;
transform: rotate(30deg);
}
SVG Default Origin
For many SVG elements without an associated CSS layout box, the default transformation origin is 0 0 rather than the center. Root SVG elements and SVG elements directly inside a foreignObject have different default-origin behavior.
When to Set an Explicit Origin
Set an explicit origin when an SVG icon, shape, or group should rotate or scale around its own center or another predictable point.
Related CSS Properties
The transform-origin property works with several properties that control transformations and animations.
transform
.example {
transform: rotate(30deg);
}
Applies rotation, scaling, translation, skewing, or other transformations.
transform-box
.example {
transform-box: border-box;
}
Selects the reference box used to calculate the transformation origin.
transform-style
.example {
transform-style: preserve-3d;
}
Controls whether transformed descendants retain their three-dimensional positioning.
rotate
.example {
rotate: 30deg;
}
Applies an individual rotation transformation.
scale
.example {
scale: 1.2;
}
Applies an individual scaling transformation.
translate
.example {
translate: 20px 10px;
}
Applies an individual translation transformation.
perspective
.scene {
perspective: 800px;
}
Applies perspective to transformed descendants.
perspective-origin
.scene {
perspective-origin: center;
}
Controls the viewpoint origin for perspective applied through the perspective property.
transition
.example {
transition: transform 0.3s ease;
}
Allows changes to the transform property to animate smoothly.
Complete Example
.example {
transform-box: border-box;
transform-origin: left center;
transform: rotate(20deg) scale(1.1);
transition: transform 0.3s ease;
}
Inheritance
The transform-origin property is not inherited. Child elements use their own transformation origin unless inheritance is explicitly requested.
Parent Element Example
.parent {
transform-origin: top left;
}
Child Element
.child {
transform-origin: center;
}
The child uses its own origin rather than automatically receiving the parent's value.
Explicit Inheritance
.child {
transform-origin: inherit;
}
Restore the Initial Value
.child {
transform-origin: initial;
}
This restores the initial value of 50% 50% 0.
Using unset
.child {
transform-origin: unset;
}
Because the property is not inherited, unset restores the initial value.
Nested Transformations
Although the property is not inherited, a transformed parent still affects the visual coordinate system of its descendants.
Practical Examples
Hinged Panel
.hinged-panel {
transform-origin: left center;
transform: rotateY(30deg);
}
Dropdown Menu Scaling
.dropdown-menu {
transform-origin: top center;
transform: scaleY(0);
transition: transform 0.2s ease;
}
.dropdown:hover .dropdown-menu {
transform: scaleY(1);
}
This illustrates the visual scaling effect. A production dropdown should also manage visibility, keyboard access, and focus rather than relying on scaling alone.
Card Hover Effect
.card {
transform-origin: center;
transition: transform 0.3s ease;
}
.card:hover {
transform: scale(1.05);
}
Rotating an Icon Around Its Corner
.icon {
display: inline-block;
transform-origin: top right;
transform: rotate(20deg);
}
Swinging Sign
.sign {
transform-origin: top center;
animation: swing 2s ease-in-out infinite alternate;
}
@keyframes swing {
from {
transform: rotate(-10deg);
}
to {
transform: rotate(10deg);
}
}
Growing Progress Indicator
.progress-fill {
transform-origin: left center;
transform: scaleX(0.75);
}
SVG Icon Rotation
svg .icon-shape {
transform-box: fill-box;
transform-origin: center;
transform: rotate(45deg);
}
3D Card Flip
.flip-card {
transform-origin: center;
transform: perspective(600px) rotateY(180deg);
}
Custom External Pivot
.orbiting-element {
transform-origin: -50px 50%;
transform: rotate(45deg);
}
Reduced Motion Alternative
@media (prefers-reduced-motion: reduce) {
.sign {
animation: none;
}
}
transform-origin Example
This example compares four identical boxes rotated by the same angle. Each box uses a different transform-origin value, demonstrating how the pivot point changes the visual result.
HTML Example
<div class="origin-demo">
<div class="origin-sample">
<strong>center</strong>
<div class="origin-stage">
<div class="origin-box origin-center">Center</div>
</div>
</div>
<div class="origin-sample">
<strong>top left</strong>
<div class="origin-stage">
<div class="origin-box origin-top-left">Top Left</div>
</div>
</div>
<div class="origin-sample">
<strong>bottom right</strong>
<div class="origin-stage">
<div class="origin-box origin-bottom-right">Bottom Right</div>
</div>
</div>
<div class="origin-sample">
<strong>25% 75%</strong>
<div class="origin-stage">
<div class="origin-box origin-custom">Custom</div>
</div>
</div>
</div>
CSS Example
.origin-demo {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(min(100%, 180px), 1fr));
gap: 16px;
}
.origin-sample strong {
display: block;
margin-bottom: 8px;
}
.origin-stage {
display: flex;
align-items: center;
justify-content: center;
min-height: 150px;
padding: 20px;
border: 1px dashed #94a3b8;
background: #f8fafc;
}
.origin-box {
display: flex;
align-items: center;
justify-content: center;
width: 90px;
height: 55px;
background: #dbeafe;
border: 2px solid #2563eb;
color: #1e40af;
font-size: 13px;
font-weight: bold;
transform: rotate(30deg);
}
.origin-center {
transform-origin: center;
}
.origin-top-left {
transform-origin: top left;
}
.origin-bottom-right {
transform-origin: bottom right;
}
.origin-custom {
transform-origin: 25% 75%;
}
Understanding the Results
All four boxes use transform: rotate(30deg). The only difference is the position of the transformation origin.
Center Origin
The first box rotates around its center.
Top-Left Origin
The second box rotates around its top-left corner.
Bottom-Right Origin
The third box rotates around its bottom-right corner.
Custom Percentage Origin
The fourth box rotates around a point positioned 25% across its reference box and 75% down.
Experiment With Another Origin
.origin-custom {
transform-origin: -20px 50%;
}
Moving the origin outside the element creates a wider rotation path.
Experiment With Scaling
.origin-top-left {
transform-origin: top left;
transform: scale(1.3);
}
The box enlarges outward from its top-left corner rather than its center.
Accessibility Considerations
The transform-origin property does not directly change an element's semantic meaning, but transformations that use it can affect readability, visibility, and interaction.
Respect Reduced Motion Preferences
Large rotations, swinging effects, and continuous scaling animations may cause discomfort for users sensitive to motion.
@media (prefers-reduced-motion: reduce) {
.animated-element {
animation: none;
transition: none;
}
}
Keep Interactive Controls Visible
Transformations around external pivot points can move controls away from their original positions.
Avoid Unexpected Overlap
Rotated and scaled elements may overlap surrounding content because transformations do not change normal document flow.
Maintain Readable Text
Extreme rotations and scaling can make text difficult to read.
Preserve Keyboard Navigation
Visual transformations do not change the document's keyboard focus order. Ensure that focusable elements remain visible and usable.
Test Browser Zoom
Verify that transformed elements remain accessible when users increase browser zoom or text size.
Provide Static Alternatives
Important information should remain available when animations are disabled.
Common Mistakes
Using Two Horizontal Keywords
.example {
transform-origin: left right;
}
Two horizontal keywords cannot be combined as the X and Y coordinates.
Using Two Vertical Keywords
.example {
transform-origin: top bottom;
}
Two vertical keywords cannot form a valid coordinate pair.
Using a Percentage for the Z Axis
.example {
transform-origin: center center 50%;
}
The third value must be a length.
Separating Values With Commas
.example {
transform-origin: 20px, 30px;
}
Separate position values with spaces.
Expecting transform-origin to Apply a Transformation
.example {
transform-origin: top left;
}
This declaration selects an origin but does not rotate, scale, or move the element by itself.
Confusing transform-origin With transform-box
The transform-origin property selects a point. The transform-box property selects the reference box used to calculate that point.
Expecting Pure Translation to Change
Changing the origin does not alter the visual result of a translation alone.
Assuming the Origin Must Be Inside the Element
Negative lengths and percentages greater than 100% can position the origin outside the reference box.
Ignoring SVG Defaults
Many SVG elements use a different default origin from ordinary HTML elements.
Ignoring the Reference Box
Percentage origins depend on the reference box selected by transform-box.
Transforming Non-Replaced Inline Elements
Ordinary non-replaced inline elements are not transformable unless their display behavior is changed.
.inline-icon {
display: inline-block;
transform-origin: center;
transform: rotate(20deg);
}
Ignoring Layout Overlap
Transforms do not change the space reserved in normal document flow.
Using Excessive Motion
Animated rotations and scaling effects should respect reduced motion preferences.
Important Considerations
Keep the following points in mind when using transform-origin:
- The property specifies the origin point for CSS transformations.
- The initial value is
50% 50% 0. - The property is not inherited.
- The property applies to transformable elements.
- One, two, or three values may be specified.
- The first coordinate identifies the horizontal position.
- The second coordinate identifies the vertical position.
- The optional third coordinate identifies the Z-axis position.
- The Z-axis coordinate must be a length.
- Keywords include
left,center,right,top, andbottom. - Percentages are relative to the selected transformation reference box.
- Lengths specify positions relative to the reference box.
- Negative lengths and percentages are allowed.
- Origins can be positioned outside an element's reference box.
- The property does not apply a transformation by itself.
- The property affects rotation and scaling.
- Pure translation is not visually affected by the origin.
- The property works with both 2D and 3D transformations.
- The
transform-boxproperty selects the reference box. - SVG elements may have different default-origin behavior.
- Transforms do not change the element's original layout space.
- Changing the origin can change the apparent position of a rotated or scaled element.
- The property can be animated.
- Use explicit origins for predictable SVG transformations.
- Test transformed elements at different viewport sizes.
- Respect reduced motion preferences for animated transformations.
Browser Support
The CSS transform-origin property is widely supported across modern browsers. Standard two-dimensional transformation origins are broadly available, while advanced SVG and three-dimensional behavior may require additional compatibility testing.
For current compatibility information, visit Can I Use? and search for transform-origin.
Basic Declaration
.example {
transform-origin: top left;
transform: rotate(30deg);
}
Percentage Origin
.example {
transform-origin: 25% 75%;
transform: scale(1.2);
}
3D Origin
.example {
transform-origin: center center 50px;
transform: perspective(600px) rotateY(30deg);
}
Feature Detection
@supports (transform-origin: 25% 75%) {
.example {
transform-origin: 25% 75%;
}
}
SVG Feature Detection
@supports (transform-box: fill-box) {
svg .shape {
transform-box: fill-box;
transform-origin: center;
}
}
Testing Recommendations
Test rotation and scaling around custom origins in the browsers your website supports. Pay particular attention to SVG reference boxes, nested transformations, 3D effects, and animations.
Specifications
The transform-origin property is defined in the CSS Transforms specifications.
CSS Transforms Module Level 1 - The transform-origin Property
These specifications define transformation origins, reference boxes, and their behavior in two-dimensional and three-dimensional transformations.
For additional documentation and examples, consult MDN Web Docs.
