The transform
CSS property lets you rotate, scale, skew, or translate an element. It modifies the coordinate space of the CSS visual formatting model.
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.
If the property has a value different than none
, a stacking context will be created. In that case, the element will act as a containing block for any position: fixed;
or position: absolute;
elements that it contains.
Only transformable elements can be transform
ed. That is, all elements whose layout is governed by the CSS box model except for: non-replaced inline boxes, table-column boxes, and table-column-group boxes.
Syntax
/* Keyword values */
transform: none;
/* Function values */
transform: matrix(1.0, 2.0, 3.0, 4.0, 5.0, 6.0);
transform: matrix3d(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
transform: perspective(17px);
transform: rotate(0.5turn);
transform: rotate3d(1, 2.0, 3.0, 10deg);
transform: rotateX(10deg);
transform: rotateY(10deg);
transform: rotateZ(10deg);
transform: translate(12px, 50%);
transform: translate3d(12px, 50%, 3em);
transform: translateX(2em);
transform: translateY(3in);
transform: translateZ(2px);
transform: scale(2, 0.5);
transform: scale3d(2.5, 1.2, 0.3);
transform: scaleX(2);
transform: scaleY(0.5);
transform: scaleZ(0.3);
transform: skew(30deg, 20deg);
transform: skewX(30deg);
transform: skewY(1.07rad);
/* Multiple function values */
transform: translateX(10px) rotate(10deg) translateY(5px);
transform: perspective(500px) translate(10px, 0, 20px) rotateY(3deg);
/* Global values */
transform: inherit;
transform: initial;
transform: unset;
The transform
property may be specified as either the keyword value none
or as one or more <transform-function>
values.
If perspective()
is one of multiple function values, it must be listed first.
Values
<transform-function>
- One or more of the CSS transform functions to be applied. The transform functions are multiplied in order from left to right, meaning that composite transforms are effectively applied in order from right to left.
none
- Specifies that no transform should be applied.
Accessibility concerns
Scaling/zooming animations are problematic for accessibility, as they are a common trigger for certain types of migraine. If you need to include such animations on your website, you should provide a control to allow users to turn off animations, preferrably site-wide.
Also, consider making use of the prefers-reduced-motion
media feature — use it to write a media query that will turn off animations if the user has reduced animation specified in their system preferences.
Find out more:
- MDN Understanding WCAG, Guideline 2.3 explanations
- Understanding Success Criterion 2.3.3 | W3C Understanding WCAG 2.1
Formal definition
Initial value | none
|
Applies to | transformable elements |
Inherited | no |
Percentages | refer to the size of bounding box |
Computed value | as specified, but with relative lengths converted into absolute lengths |
Animation type | a transform |
Creates stacking context | yes |
Formal syntax
none | <transform-list>where <transform-list> = <transform-function>+where <transform-function> = <matrix()> | <translate()> | <translateX()> | <translateY()> | <scale()> | <scaleX()> | <scaleY()> | <rotate()> | <skew()> | <skewX()> | <skewY()> | <matrix3d()> | <translate3d()> | <translateZ()> | <scale3d()> | <scaleZ()> | <rotate3d()> | <rotateX()> | <rotateY()> | <rotateZ()> | <perspective()>where <matrix()> = matrix( <number>#{6} )<translate()> = translate( <length-percentage> , <length-percentage>? )<translateX()> = translateX( <length-percentage> )<translateY()> = translateY( <length-percentage> )<scale()> = scale( <number> , <number>? )<scaleX()> = scaleX( <number> )<scaleY()> = scaleY( <number> )<rotate()> = rotate( [ <angle> | <zero> ] )<skew()> = skew( [ <angle> | <zero> ] , [ <angle> | <zero> ]? )<skewX()> = skewX( [ <angle> | <zero> ] )<skewY()> = skewY( [ <angle> | <zero> ] )<matrix3d()> = matrix3d( <number>#{16} )<translate3d()> = translate3d( <length-percentage> , <length-percentage> , <length> )<translateZ()> = translateZ( <length> )<scale3d()> = scale3d( <number> , <number> , <number> )<scaleZ()> = scaleZ( <number> )<rotate3d()> = rotate3d( <number> , <number> , <number> , [ <angle> | <zero> ] )<rotateX()> = rotateX( [ <angle> | <zero> ] )<rotateY()> = rotateY( [ <angle> | <zero> ] )<rotateZ()> = rotateZ( [ <angle> | <zero> ] )<perspective()> = perspective( <length> )where <length-percentage> = <length> | <percentage>
Examples
Translating and rotating an element
HTML
<div>Transformed element</div>
CSS
div {
border: solid red;
transform: translate(30px, 20px) rotate(20deg);
width: 140px;
height: 60px;
}
Result
More examples
Please see Using CSS transforms and <transform-function>
for more examples.
Specifications
Specification | Status | Comment |
---|---|---|
CSS Transforms Level 2The definition of 'transform' in that specification. | Editor's Draft | Adds 3D transform functions. |
CSS Transforms Level 1The definition of 'transform' in that specification. | Working Draft | Initial definition. |
Browser compatibility
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.
Update compatibility data on GitHub
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
transform
|
Chrome Full support 36 Full support 36 Full support 1 Prefixed' Implemented with the vendor prefix: -webkit- |
Edge Full support 12 Full support 12 Full support 12 Prefixed' Implemented with the vendor prefix: -webkit- |
Firefox Full support 16 Full support 16 Full support 49 Prefixed' Implemented with the vendor prefix: -webkit- Full support 44 Prefixed' Implemented with the vendor prefix: -webkit-
Disabled' From version 44: this feature is behind the |
IE Full support 10 Full support 10 Notes' Internet Explorer does not support the global values Prefixed' Implemented with the vendor prefix: -webkit- Full support 9 Prefixed' Implemented with the vendor prefix: -ms- Notes' Internet Explorer 5.5 or later supports a proprietary Matrix Filter which can be used to achieve a similar effect. |
Opera Full support 23 Full support 23 Full support 15 Prefixed' Implemented with the vendor prefix: -webkit- No support 12.1 — 15 No support 10.5 — 15 Prefixed' Implemented with the vendor prefix: -o- |
Safari Full support 9 Full support 9 Full support 3.1 Prefixed' Implemented with the vendor prefix: -webkit- |
WebView Android Full support 37 Full support 37 Full support 2 Prefixed' Implemented with the vendor prefix: -webkit-
Notes' Android 2.3 has a bug where input forms will "jump" when typing, if any container element has a |
Chrome Android Full support 36 Full support 36 Full support 18 Prefixed' Implemented with the vendor prefix: -webkit- |
Firefox Android Full support 16 Full support 16 Full support 49 Prefixed' Implemented with the vendor prefix: -webkit- Full support 44 Prefixed' Implemented with the vendor prefix: -webkit-
Disabled' From version 44: this feature is behind the |
Opera Android Full support 24 Full support 24 Full support 14 Prefixed' Implemented with the vendor prefix: -webkit- No support 12.1 — 14 No support 11 — 14 Prefixed' Implemented with the vendor prefix: -o- |
Safari iOS Full support 9 Full support 9 Full support 3.2 Prefixed' Implemented with the vendor prefix: -webkit- |
Samsung Internet Android Full support 3.0 Full support 3.0 Full support 1.0 Prefixed' Implemented with the vendor prefix: -webkit- |
3D support | Chrome
Full support 12 |
Edge
Full support 12 |
Firefox
Full support 16 |
IE Full support 10 Full support 10 Notes' Internet Explorer 9.0 or earlier has no support for 3D transforms. Mixing 3D and 2D transform functions, such as |
Opera
Full support 15 |
Safari
Full support 4 |
WebView Android Full support 3 Full support 3 Prefixed' Implemented with the vendor prefix: -webkit- |
Chrome Android
Full support 18 |
Firefox Android
Full support 16 |
Opera Android
Full support 14 |
Safari iOS
Full support 3.2 |
Samsung Internet Android
Full support 1.0 |
Legend
- Full support
- Full support
- See implementation notes.'
- See implementation notes.
- User must explicitly enable this feature.'
- User must explicitly enable this feature.
- Requires a vendor prefix or different name for use.'
- Requires a vendor prefix or different name for use.
See also
- Using CSS transforms
<transform-function>
data type with all the transform functions explained.- Online tool to visualize CSS Transform functions: CSS Transform Playground
transform by Mozilla Contributors is licensed under CC-BY-SA 2.5.