CSS - transform

The CSS transform property lets you modify the coordinate space of the CSS visual formatting model. Using it, elements can be translated, rotated, scaled, and skewed.

Example

 

See Using CSS transforms.

Syntax  

CSS
/* Keyword values */
transform: none;

/* Function values */
transform: matrix(1.0, 2.0, 3.0, 4.0, 5.0, 6.0);
transform: translate(12px, 50%);
transform: translateX(2em);
transform: translateY(3in);
transform: scale(2, 0.5);
transform: scaleX(2);
transform: scaleY(0.5);
transform: rotate(0.5turn);
transform: skew(30deg, 20deg);
transform: skewX(30deg);
transform: skewY(1.07rad);
transform: matrix3d(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0);
transform: translate3d(12px, 50%, 3em);
transform: translateZ(2px);
transform: scale3d(2.5, 1.2, 0.3);
transform: scaleZ(0.3);
transform: rotate3d(1, 2.0, 3.0, 10deg);
transform: rotateX(10deg);
transform: rotateY(10deg);
transform: rotateZ(10deg);
transform: perspective(17px);

/* Multiple function values */
transform: translateX(10px) rotate(10deg) translateY(5px);

/* Global values */
transform: inherit;
transform: initial;
transform: unset;

Values

<transform-function>
One or more of the CSS transform functions to be applied, see below.
none
Specifies that no transform should be applied.

Formal syntax

CSS
none <a href="css/value_definition_syntax#single_bar" title="Single bar">|</a> <a href="css/transform#transform-list"><transform-list></a><p>where <br><code><transform-list> = <a href="css/transform-function" title="Possible values: matrix(), matrix3d(), rotate(), rotate3d(), rotateX(), rotateY(), rotateZ(), scale(), scale3d(), scaleX(), scaleY(), scaleZ(), skewX(), skewY(), translate(), translate3d(), translateX(), translateY(), translateZ()"><transform-function></a><a href="css/value_definition_syntax#plus_(.2b)" title="Plus">+</a></code></p><p>where <br><code><transform-function> = <a href="css/value_definition_syntax#brackets" title="Brackets">[</a> <a href="css/transform#matrix()"><matrix()></a> <a href="css/value_definition_syntax#double_bar" title="Double bar">||</a> <a href="css/transform#translate()"><translate()></a> <a href="css/value_definition_syntax#double_bar" title="Double bar">||</a> <a href="css/transform#translateX()"><translateX()></a> <a href="css/value_definition_syntax#double_bar" title="Double bar">||</a> <a href="css/transform#translateY()"><translateY()></a> <a href="css/value_definition_syntax#double_bar" title="Double bar">||</a> <a href="css/transform#scale()"><scale()></a> <a href="css/value_definition_syntax#double_bar" title="Double bar">||</a> <a href="css/transform#scaleX()"><scaleX()></a> <a href="css/value_definition_syntax#double_bar" title="Double bar">||</a> <a href="css/transform#scaleY()"><scaleY()></a> <a href="css/value_definition_syntax#double_bar" title="Double bar">||</a> <a href="css/transform#rotate()"><rotate()></a> <a href="css/value_definition_syntax#double_bar" title="Double bar">||</a> <a href="css/transform#skew()"><skew()></a> <a href="css/value_definition_syntax#double_bar" title="Double bar">||</a> <a href="css/transform#skewX()"><skewX()></a> <a href="css/value_definition_syntax#double_bar" title="Double bar">||</a> <a href="css/transform#skewY()"><skewY()></a> <a href="css/value_definition_syntax#double_bar" title="Double bar">||</a> <a href="css/transform#matrix3d()"><matrix3d()></a> <a href="css/value_definition_syntax#double_bar" title="Double bar">||</a> <a href="css/transform#translate3d()"><translate3d()></a> <a href="css/value_definition_syntax#double_bar" title="Double bar">||</a> <a href="css/transform#translateZ()"><translateZ()></a> <a href="css/value_definition_syntax#double_bar" title="Double bar">||</a> <a href="css/transform#scale3d()"><scale3d()></a> <a href="css/value_definition_syntax#double_bar" title="Double bar">||</a> <a href="css/transform#scaleZ()"><scaleZ()></a> <a href="css/value_definition_syntax#double_bar" title="Double bar">||</a> <a href="css/transform#rotate3d()"><rotate3d()></a> <a href="css/value_definition_syntax#double_bar" title="Double bar">||</a> <a href="css/transform#rotateX()"><rotateX()></a> <a href="css/value_definition_syntax#double_bar" title="Double bar">||</a> <a href="css/transform#rotateY()"><rotateY()></a> <a href="css/value_definition_syntax#double_bar" title="Double bar">||</a> <a href="css/transform#rotateZ()"><rotateZ()></a> <a href="css/value_definition_syntax#double_bar" title="Double bar">||</a> <a href="css/transform#perspective()"><perspective()></a> <a href="css/value_definition_syntax#brackets" title="Brackets">]</a><a href="css/value_definition_syntax#plus_(.2b)" title="Plus">+</a></code></p><p>where <br><code><matrix()> = matrix( <a href="css/number" title=""><number></a> <a href="css/value_definition_syntax#brackets" title="Brackets">[</a>, <a href="css/number" title=""><number></a> <a href="css/value_definition_syntax#brackets" title="Brackets">]</a><a href="css/value_definition_syntax#curly_braces_(.7b_.7d)" title="Curly braces">{</a>5,5<a href="css/value_definition_syntax#curly_braces_(.7b_.7d)" title="Curly braces">}</a> )<br><translate()> = translate( <a href="css/transform#length-percentage"><length-percentage></a> <a href="css/value_definition_syntax#brackets" title="Brackets">[</a>, <a href="css/transform#length-percentage"><length-percentage></a> <a href="css/value_definition_syntax#brackets" title="Brackets">]</a><a href="css/value_definition_syntax#question_mark_(.3f)" title="Question mark">?</a> )<br><translateX()> = translateX( <a href="css/transform#length-percentage"><length-percentage></a> )<br><translateY()> = translateY( <a href="css/transform#length-percentage"><length-percentage></a> )<br><scale()> = scale( <a href="css/number" title=""><number></a> <a href="css/value_definition_syntax#brackets" title="Brackets">[</a>, <a href="css/number" title=""><number></a> <a href="css/value_definition_syntax#brackets" title="Brackets">]</a><a href="css/value_definition_syntax#question_mark_(.3f)" title="Question mark">?</a> )<br><scaleX()> = scaleX( <a href="css/number" title=""><number></a> )<br><scaleY()> = scaleY( <a href="css/number" title=""><number></a> )<br><rotate()> = rotate( <a href="css/angle" title="Possible values: a number followed by'deg', 'grad', 'rad' or 'turn', like 2turn, 1.3rad, -60deg or 0grad."><angle></a> )<br><skew()> = skew( <a href="css/angle" title="Possible values: a number followed by'deg', 'grad', 'rad' or 'turn', like 2turn, 1.3rad, -60deg or 0grad."><angle></a> <a href="css/value_definition_syntax#brackets" title="Brackets">[</a>, <a href="css/angle" title="Possible values: a number followed by'deg', 'grad', 'rad' or 'turn', like 2turn, 1.3rad, -60deg or 0grad."><angle></a> <a href="css/value_definition_syntax#brackets" title="Brackets">]</a><a href="css/value_definition_syntax#question_mark_(.3f)" title="Question mark">?</a> )<br><skewX()> = skewX( <a href="css/angle" title="Possible values: a number followed by'deg', 'grad', 'rad' or 'turn', like 2turn, 1.3rad, -60deg or 0grad."><angle></a> )<br><skewY()> = skewY( <a href="css/angle" title="Possible values: a number followed by'deg', 'grad', 'rad' or 'turn', like 2turn, 1.3rad, -60deg or 0grad."><angle></a> )<br><matrix3d()> = matrix3d( <a href="css/number" title=""><number></a> <a href="css/value_definition_syntax#brackets" title="Brackets">[</a>, <a href="css/number" title=""><number></a> <a href="css/value_definition_syntax#brackets" title="Brackets">]</a><a href="css/value_definition_syntax#curly_braces_(.7b_.7d)" title="Curly braces">{</a>15,15<a href="css/value_definition_syntax#curly_braces_(.7b_.7d)" title="Curly braces">}</a> )<br><translate3d()> = translate3d( <a href="css/transform#length-percentage"><length-percentage></a> , <a href="css/transform#length-percentage"><length-percentage></a> , <a href="css/length" title="Possible values: a number followed by'em', 'ex', 'ch', 'rem', 'px', 'cm', 'mm', 'in', 'vh', 'vw', 'vmin', 'vmax', 'pt', 'pc' or 'px', like 3px, 1.5cm, -0.5em or 0"><length></a> )<br><translateZ()> = translateZ( <a href="css/length" title="Possible values: a number followed by'em', 'ex', 'ch', 'rem', 'px', 'cm', 'mm', 'in', 'vh', 'vw', 'vmin', 'vmax', 'pt', 'pc' or 'px', like 3px, 1.5cm, -0.5em or 0"><length></a> )<br><scale3d()> = scale3d( <a href="css/number" title=""><number></a> , <a href="css/number" title=""><number></a>, <a href="css/number" title=""><number></a> )<br><scaleZ()> = scaleZ( <a href="css/number" title=""><number></a> )<br><rotate3d()> = rotate3d( <a href="css/number" title=""><number></a> , <a href="css/number" title=""><number></a> , <a href="css/number" title=""><number></a> , <a href="css/angle" title="Possible values: a number followed by'deg', 'grad', 'rad' or 'turn', like 2turn, 1.3rad, -60deg or 0grad."><angle></a> )<br><rotateX()> = rotateX( <a href="css/angle" title="Possible values: a number followed by'deg', 'grad', 'rad' or 'turn', like 2turn, 1.3rad, -60deg or 0grad."><angle></a> )<br><rotateY()> = rotateY( <a href="css/angle" title="Possible values: a number followed by'deg', 'grad', 'rad' or 'turn', like 2turn, 1.3rad, -60deg or 0grad."><angle></a> )<br><rotateZ()> = rotateZ( <a href="css/angle" title="Possible values: a number followed by'deg', 'grad', 'rad' or 'turn', like 2turn, 1.3rad, -60deg or 0grad."><angle></a> )<br><perspective()> = perspective( <a href="css/length" title="Possible values: a number followed by'em', 'ex', 'ch', 'rem', 'px', 'cm', 'mm', 'in', 'vh', 'vw', 'vmin', 'vmax', 'pt', 'pc' or 'px', like 3px, 1.5cm, -0.5em or 0"><length></a> )</code></p><p>where <br><code><length-percentage> = <a href="css/length" title="Possible values: a number followed by'em', 'ex', 'ch', 'rem', 'px', 'cm', 'mm', 'in', 'vh', 'vw', 'vmin', 'vmax', 'pt', 'pc' or 'px', like 3px, 1.5cm, -0.5em or 0"><length></a> <a href="css/value_definition_syntax#single_bar" title="Single bar">|</a> <a href="css/percentage" title=""><percentage></a></code></p>

Description  

The CSS transform property lets you modify the coordinate space of the CSS visual formatting model. Using it, elements can be translated, rotated, scaled, and skewed.

If the property has a value different than none, a stacking context will be created. In that case the object will act as a containing block for position: fixed elements that it contains.

Initial valuenone
Applies totransformable elements
Inheritedno
Percentagesrefer to the size of bounding box
Mediavisual
Computed valueas specified, but with relative lengths converted into absolute lengths
Animation typea transform
Canonical orderthe unique non-ambiguous order defined by the formal grammar
Creates stacking contextyes

Browser Compatibility  

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support (Yes) -webkit
36
3.5 (1.9.1)-moz[1]
16.0 (16.0)[2]
9.0-ms[3]
10.0
10.5-o
12.10
15.0-webkit
23
3.1-webkit
3D Support 12.0-webkit
36
10.0-moz
16.0 (16.0)
10.0 15.0-webkit
23
4.0-webkit
Feature Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support 2.1-webkit[4] (Yes)-webkit (Yes) (Yes)
11.0-webkit[5]
11.5-webkit 3.2 (Yes)-webkit
3D Support 3.0-webkit (Yes)-webkit (Yes) (Yes) 22-webkit 3.2 (Yes)-webkit

[1] Gecko 14.0 removed the experimental support for skew(), but it was reintroduced in Gecko 15.0 for compatibility reasons. As it is non-standard and will likely be removed in the future, do not use it.

[2] Before Firefox 16, the translation values of matrix() and matrix3d() could be <length>, in addition to the standard <number>.

In addition to the unprefixed support, Gecko 44.0 (Firefox 44.0 / Thunderbird 44.0 / SeaMonkey 2.41) added support for a -webkit prefixed version of the property for web compatibility reasons behind the preference layout.css.prefixes.webkit, defaulting to false. Since Gecko 49.0 (Firefox 49.0 / Thunderbird 49.0 / SeaMonkey 2.46) the preference defaults to true.

[3] Internet Explorer 5.5 or later supports a proprietary Matrix Filter which can be used to achieve a similar effect.

Internet Explorer 9.0 or earlier has no support for 3D transforms. Mixing 3D and 2D transform functions, such as -ms-transform:rotate(10deg) translateZ(0);, will prevent the entire property from being applied.

Internet Explorer does not support the global values initial and unset.

[4] Android 2.3 has a bug where input forms will "jump" when typing, if any container element has a -webkit-transform.

[5] Internet Explorer 11.0 supports the -webkit prefixed variant as an alias for the default one.

See Also  

Specifications  

Specification Status Comment
CSS Transforms Level 1
The definition of 'transform' in that specification.
Working Draft Initial definition

 

HTML Content

HTML
<p>Transformed element</p>

CSS Content

CSS
p {
  border: solid red;

  -webkit-transform: translate(100px) rotate(20deg);
  -webkit-transform-origin: 0 -250px;

  transform: translate(100px) rotate(20deg);
  transform-origin: 0 -250px;
}

License

© 2016 Mozilla Contributors
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-us/docs/web/css/transform

CSS CSS Property Experimental NeedsBrowserCompatibility Property Reference Transforms