transform-origin CSS property sets the origin for an element's transformations.

The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request.

The transformation origin is the point around which a transformation is applied. For example, the transformation origin of the rotate() function is the center of rotation.

This property is applied by first translating the element by the value of the property, then applying the element's transform, then translating by the negated property value.
This means, this definition

transform-origin: -100% 50%;
transform: rotate(45deg);
					

results in the same transformation as

transform-origin: 0 0;
transform: translate(-100%, 50%) rotate(45deg) translate(100%, -50%);
					

By default, the origin of a transform is center .

句法

/* One-value syntax */
transform-origin: 2px;
transform-origin: bottom;
/* x-offset | y-offset */
transform-origin: 3cm 2px;
/* x-offset-keyword | y-offset */
transform-origin: left 2px;
/* x-offset-keyword | y-offset-keyword */
transform-origin: right top;
/* y-offset-keyword | x-offset-keyword */
transform-origin: top right;
/* x-offset | y-offset | z-offset */
transform-origin: 2px 30% 10px;
/* x-offset-keyword | y-offset | z-offset */
transform-origin: left 5px -3px;
/* x-offset-keyword | y-offset-keyword | z-offset */
transform-origin: right bottom 2cm;
/* y-offset-keyword | x-offset-keyword | z-offset */
transform-origin: bottom right 2cm;
/* Global values */
transform-origin: inherit;
transform-origin: initial;
transform-origin: unset;
					

transform-origin property may be specified using one, two, or three values, where each value represents an offset. Offsets that are not explicitly defined are reset to their corresponding initial values .

If two or more values are defined and either no value is a keyword, or the only used keyword is center , then the first value represents the horizontal offset and the second represents the vertical offset.

  • One-value syntax:
  • Two-value syntax:
  • Three-value syntax:
    • The first two values are the same as for the two-value syntax.
    • The third value must be a <length> . It always represents the Z offset.

x-offset
<length> <percentage> describing how far from the left edge of the box the origin of the transform is set.
offset-keyword
Is one of the left , right , top , bottom ,或 center keyword describing the corresponding offset.
y-offset
<length> <percentage> describing how far from the top edge of the box the origin of the transform is set.
x-offset-keyword
Is one of the left , right ,或 center keyword describing how far from the left edge of the box the origin of the transform is set.
y-offset-keyword
Is one of the top , bottom ,或 center keyword describing how far from the top edge of the box the origin of the transform is set.
z-offset
<length> (and never a <percentage> which would make the statement invalid) describing how far from the user eye the z=0 origin is set.

The keywords are convenience shorthands and match the following <percentage> values:

Keyword Value
left 0%
center 50%
right 100%
top 0%
bottom 100%

形式定义

初始值 50% 50% 0
适用于 transformable elements
继承 no
百分比 refer to the size of bounding box
计算值 for <length> the absolute value, otherwise a percentage
动画类型 simple list of length, percentage, or calc

形式句法

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

where
<length-percentage> = <length> | <percentage>

范例

A demonstration of various transform values

代码 Sample
transform: none;
<div class="box1"> </div>
									
.box1 {
margin: 0.5em;
width: 3em;
height: 3em;
border: solid 1px;
background-color: palegreen;
transform: none;
-webkit-transform: none;
}
									
transform: rotate(30deg);
<div class="box2"> </div>
									
.box2 {
margin: 0.5em;
width: 3em;
height: 3em;
border: solid 1px;
background-color: palegreen;
transform: rotate(30deg);
-webkit-transform: rotate(30deg);
}
									
transform: rotate(30deg);
transform-origin: 0 0;
<div class="box3"> </div>
									
.box3 {
margin: 0.5em;
width: 3em;
height: 3em;
border: solid 1px;
background-color: palegreen;
transform-origin: 0 0;
-webkit-transform-origin: 0 0;
transform: rotate(30deg);
-webkit-transform: rotate(30deg);
}
									
transform: rotate(30deg);
transform-origin: 100% 100%;
<div class="box4"> </div>
									
.box4 {
margin: 0.5em;
width: 3em;
height: 3em;
border: solid 1px;
background-color: palegreen;
transform-origin: 100% 100%;
-webkit-transform-origin: 100% 100%;
transform: rotate(30deg);
-webkit-transform: rotate(30deg);
}
									
transform: rotate(30deg);
transform-origin: -1em -3em;
<div class="box5"> </div>
									
.box5 {
margin: 0.5em;
width: 3em;
height: 3em;
border: solid 1px;
background-color: palegreen;
transform-origin: -1em -3em;
-webkit-transform-origin: -1em -3em;
transform: rotate(30deg);
-webkit-transform: rotate(30deg);
}
									
transform: scale(1.7);
<div class="box6"> </div>
									
.box6 {
margin: 0.5em;
width: 3em;
height: 3em;
border: solid 1px;
background-color: palegreen;
transform: scale(1.7);
-webkit-transform: scale(1.7);
}
									
transform: scale(1.7);
transform-origin: 0 0;
<div class="box7"> </div>
									
.box7 {
margin: 0.5em;
width: 3em;
height: 3em;
border: solid 1px;
background-color: palegreen;
transform: scale(1.7);
-webkit-transform: scale(1.7);
transform-origin: 0 0;
-webkit-transform-origin: 0 0;
}
									
transform: scale(1.7);
transform-origin: 100% -30%;
<div class="box8"> </div>
									
.box8 {
margin: 0.5em;
width: 3em;
height: 3em;
border: solid 1px;
background-color: palegreen;
transform: scale(1.7);
-webkit-transform: scale(1.7);
transform-origin: 100% -30%;
-webkit-transform-origin: 100% -30%;
}
									
transform: skewX(50deg);
transform-origin: 100% -30%;
<div class="box9"> </div>
									
.box9 {
margin: 0.5em;
width: 3em;
height: 3em;
border: solid 1px;
background-color: palegreen;
transform: skewX(50deg);
-webkit-transform: skewX(50deg);
transform-origin: 100% -30%;
-webkit-transform-origin: 100% -30%;
}
									
transform: skewY(50deg);
transform-origin: 100% -30%;
<div class="box10"> </div>
									
.box10 {
margin: 0.5em;
width: 3em;
height: 3em;
border: solid 1px;
background-color: palegreen;
transform: skewY(50deg);
-webkit-transform: skewY(50deg);
transform-origin: 100% -30%;
-webkit-transform-origin: 100% -30%;
}
									

规范

规范 状态 注释
CSS Transforms Level 1
The definition of 'transform-origin' in that specification.
工作草案

浏览器兼容性

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
transform-origin Chrome 完整支持 36 Edge 完整支持 12 Firefox 完整支持 16
完整支持 16
完整支持 3.5 Prefixed
Prefixed Implemented with the vendor prefix: -moz-
preference (needs to be set to ). To change preferences in Firefox, visit about:config.
IE 完整支持 10
完整支持 10
完整支持 9 Prefixed
Prefixed Implemented with the vendor prefix: -ms-
Opera 完整支持 23
完整支持 23
Prefixed Implemented with the vendor prefix: -webkit-
不支持 12.1 — 15
完整支持 10.5 Prefixed
Prefixed Implemented with the vendor prefix: -o-
Safari 完整支持 9 WebView Android 完整支持 37 Chrome Android 完整支持 36 Firefox Android 完整支持 16
完整支持 16
完整支持 4 Prefixed
Prefixed Implemented with the vendor prefix: -moz-
preference (needs to be set to ). To change preferences in Firefox, visit about:config.
Opera Android 完整支持 24
完整支持 24
Prefixed Implemented with the vendor prefix: -webkit-
不支持 12.1 — 15
完整支持 11 Prefixed
Prefixed Implemented with the vendor prefix: -o-
Safari iOS 完整支持 9 Samsung Internet Android 完整支持 3.0
Support in SVG Chrome 完整支持 19 Edge 完整支持 17 Firefox 完整支持 43 注意事项
完整支持 43 注意事项
注意事项 Keywords and percentages refer to the canvas instead of the object itself. See bug 1209061 .
不支持 41 — 43 注意事项 Disabled
注意事项 Keywords and percentages refer to the canvas instead of the object itself. See bug 1209061 .
Disabled ). To change preferences in Firefox, visit about:config.
IE 不支持 No Opera 完整支持 15 Safari 完整支持 6 注意事项
完整支持 6 注意事项
注意事项 Only supported for transformations applied using the CSS transform property (e.g. .className { transform: rotate(45deg); transform-origin: center; } ). It has no effect on transformations applied using the transform SVG attribute (e.g. <rect style="transform-origin: center;" transform="rotate(45)" /> ).
WebView Android 完整支持 ≤37 Chrome Android 完整支持 25 Firefox Android 完整支持 43 注意事项
完整支持 43 注意事项
注意事项 Keywords and percentages refer to the canvas instead of the object itself. See bug 1209061 .
不支持 41 — 43 注意事项 Disabled
注意事项 Keywords and percentages refer to the canvas instead of the object itself. See bug 1209061 .
Disabled ). To change preferences in Firefox, visit about:config.
Opera Android 完整支持 14 Safari iOS 完整支持 6 注意事项
完整支持 6 注意事项
注意事项 Only supported for transformations applied using the CSS transform property (e.g. .className { transform: rotate(45deg); transform-origin: center; } ). It has no effect on transformations applied using the transform SVG attribute (e.g. <rect style="transform-origin: center;" transform="rotate(45)" /> ).
Samsung Internet Android 完整支持 1.5
Three-value syntax Chrome 完整支持 12 Edge 完整支持 12 Firefox 完整支持 10 IE 完整支持 9 Opera 完整支持 15 Safari 完整支持 5 WebView Android 完整支持 ≤37 Chrome Android 完整支持 18 Firefox Android 完整支持 10 Opera Android 完整支持 14 Safari iOS 完整支持 3.2 Samsung Internet Android 完整支持 1.0

图例

完整支持

完整支持

不支持

不支持

见实现注意事项。

见实现注意事项。

用户必须明确启用此特征。

用户必须明确启用此特征。

要求使用供应商前缀或不同名称。

要求使用供应商前缀或不同名称。

另请参阅

元数据

  • 最后修改:
  1. CSS
  2. CSS 参考
  3. CSS Transforms
  4. 指南
    1. Using CSS transforms
  5. 特性
    1. <transform-function>
    2. backface-visibility
    3. perspective
    4. perspective-origin
    5. rotate
    6. scale
    7. transform
    8. transform-box
    9. transform-origin
    10. transform-style
    11. translate

Copyright  © 2014-2026 乐数软件    

工业和信息化部: 粤ICP备14079481号-1