transform

« CSS « CSS Reference

Summary

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

Syntax

transform:  <transform-function> [<transform-function>]* | none

Vendor prefixes: See the compatibility table below for detail on the vendor prefixes you'll need to use for this feature.

Values

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

Examples

See Using CSS transforms.

Live Example

 

 

 

pre {
     width: 33em;
     border: solid red;

    -moz-transform: translate(100px) rotate(20deg);
    -moz-transform-origin: 60% 100%;

    -webkit-transform: translate(100px) rotate(20deg);
    -webkit-transform-origin: 60% 100%;

    -o-transform:translate(100px) rotate(20deg); 
    -o-transform-origin:60% 100%;

    -ms-transform: translate(100px) rotate(20deg);
    -ms-transform-origin: 60% 100%;

    transform: translate(100px) rotate(20deg);
    transform-origin: 60% 100%;
}



CSS transform functions

The transform CSS property allows the coordinate system used by an element to be manipulated using transform functions. These functions are described below.

matrix

transform:  matrix(a, c, b, d, tx, ty)

/* Where a, b, c, d build the transformation matrix 
   ┌     ┐ 
   │ a b │
   │ c d │
   └     ┘
   and tx, ty are the translate values.  */

Specifies a 2D transformation matrix comprised of the specified six values. This is the equivalent to applying the transformation matrix [a b c d tx ty].

Note: Gecko (Firefox) accepts a <length> value for tx and ty.
Webkit (Safari, Chrome) and Opera currently support a unitless <number> for tx and ty.

Live Examples

 

 

 background: gold;  width: 30em;

    -moz-transform: matrix(1, -0.2, 0, 1, 0, 0);
 -webkit-transform: matrix(1, -0.2, 0, 1, 0, 0);
      -o-transform: matrix(1, -0.2, 0, 1, 0, 0);
     -ms-transform: matrix(1, -0.2, 0, 1, 0, 0);
         transform: matrix(1, -0.2, 0, 1, 0, 0);
 background: wheat;
 max-width: intrinsic;

    -moz-transform: matrix(1, 0, 0.6, 1, 15em, 0);
 -webkit-transform: matrix(1, 0, 0.6, 1,  250, 0);
      -o-transform: matrix(1, 0, 0.6, 1,  250, 0);
     -ms-transform: matrix(1, 0, 0.6, 1,  250, 0);
         transform: matrix(1, 0, 0.6, 1,  250, 0);

rotate

transform:  rotate(angle);       /* an <angle>, e.g.  rotate(30deg) */

Rotates the element clockwise around its origin (as specified by the transform-origin property) by the specified angle. The operation corresponds to the matrix [cos(angle) sin(angle) -sin(angle) cos(angle) 0 0].

scale

transform:  scale(sx[, sy]);     /* one or two unitless <number>s, e.g.  scale(2.1,4) */

Specifies a 2D scaling operation described by [sx, sy]. If sy isn't specified, it is assumed to be equal to sx.

scaleX

transform:  scaleX(sx);          /* a unitless <number>, e.g.  scaleX(2.7) */

Specifies a scale operation using the vector [sx, 1].

scaleY

transform:  scaleY(sy)           /* a unitless <number>, e.g.  scaleY(0.3) */

Specifies a scale operation using the vector [1, sy].

skew Non-standard

transform:  skew(ax[, ay])       /* one or two <angle>s, e.g.  skew(30deg,-10deg) */

Skews the element around the X and Y axes by the specified angles. If ay isn't provided, no skew is performed on the Y axis.

The skew() function was present in early drafts. It has been removed and is still present in some prefixed implementations. Do not use it.

skewX

transform:  skewX(angle)         /* an <angle>, e.g.  skewX(-30deg) */

Skews the element around the X axis by the given angle.

skewY

transform:  skewY(angle)         /* an <angle>, e.g.  skewY(4deg) */

Skews the element around the Y axis by the given angle.

translate

transform:  translate(tx[, ty])  /* one or two <length> values */

Specifies a 2D translation by the vector [tx, ty]. If ty isn't specified, its value is assumed to be zero.

translateX

transform:  translateX(tx)       /* see <length> for possible values */

Translates the element by the given amount along the X axis.

translateY

transform:  translateY(ty)       /* see <length> for possible values */

Translates the element by the given amount along the Y axis.

Browser compatibility

  • Desktop
  • Mobile

Feature Firefox (Gecko) Chrome Internet Explorer Opera Safari
Basic support 3.5 (1.9.1) -moz yes -webkit 9.0 -ms 10.5 -o 3.1 -webkit
3D Support 10.0 -moz 12.0 -webkit 10.0 -ms no 4.0 -webkit
Feature iOS Safari Opera Mini Opera Mobile Android Browser
Basic support ? ? ? ?

Notes

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

Gecko 14.0 removed the experimental support for skew().

See also

 

Tags (6)

Edit tags

Attachments (0)

 

Attach file