Transforms & motion path

The properties that move, rotate, scale and skew a box after layout, place it in 3D space, or send it along a path. Transforms change how a box is painted, not where it sits in the layout, so neighbouring content does not move. The functions that go inside transform (translate(), rotate(), matrix() and the rest) are under Transform functions; animating these properties is covered in Transitions & animation.

Transforms

transform

Applies a list of transform functions to a box. The functions are applied in order, so translate(10px) rotate(45deg) and rotate(45deg) translate(10px) give different results.

Syntaxnone | <transform-list>
Initialnone
Applies toTransformable elements
InheritedNo
PercentagesRefer to the size of the reference box
AnimationAs a transform list, following the transform interpolation rules
SupportChrome 36 · Firefox 16 · Safari 9
Speccss-transforms-1

A <transform-list> is one or more transform functions separated by spaces. Any value other than none makes the box a containing block for its absolutely and fixed positioned descendants and creates a stacking context.

transform: translate(-50%, -50%) rotate(-3deg);
Pull a box back by half its own size, then tilt it slightly.

transform-origin

The fixed point that transforms happen around: the centre of a rotation or scale. One or two values set the x and y position like background-position; an optional third length sets the z position.

Syntax[ left | center | right | top | bottom | <length-percentage> ] | [ left | center | right | <length-percentage> ] [ top | center | bottom | <length-percentage> ] <length>? | [ [ center | left | right ] && [ center | top | bottom ] ] <length>?
Initial50% 50%
Applies toTransformable elements
InheritedNo
PercentagesRefer to the size of the reference box
AnimationBy computed value
SupportChrome 36 · Firefox 16 · Safari 9
Speccss-transforms-1

It also applies to the individual translate, rotate and scale properties. transform-origin: top left makes a box rotate around its top-left corner.

transform-box

Chooses the reference box that transform-origin and percentage values in transforms are measured against. It matters mostly for SVG elements, where the default measures from the SVG viewport rather than the shape itself.

Syntaxcontent-box | border-box | fill-box | stroke-box | view-box
Initialview-box
Applies toTransformable elements
InheritedNo
AnimationDiscrete
SupportChrome 64 · Firefox 55 · Safari 11
Speccss-transforms-1

For elements with a CSS layout box, fill-box is used as content-box, and stroke-box and view-box are used as border-box. So on HTML elements the default is the border box.

svg .gear { transform-box: fill-box; transform-origin: center; }
Spin an SVG shape around its own centre instead of the SVG's origin.

Individual transforms

translate

Moves a box without writing a full transform. One value moves along x; two move along x and y; a third length moves along z.

Syntaxnone | <length-percentage> [ <length-percentage> <length>? ]?
Initialnone
Applies toTransformable elements
InheritedNo
PercentagesRelative to the width of the reference box (first value) or its height (second value)
AnimationBy computed value; none is treated as no translation
SupportChrome 104 · Firefox 72 · Safari 14.1
Speccss-transforms-2

The individual properties combine with transform in a fixed order: translate, then rotate, then scale, then the transform list. Because each is its own property, a hover rule can change one of them without repeating or undoing the others, and each can be transitioned on its own timing.

.card { rotate: -2deg; transition: translate 0.2s; }
.card:hover { translate: 0 -4px; } /* the rotation is kept */
Lift a tilted card on hover without restating its rotation.

rotate

Rotates a box. A bare angle rotates in the plane of the screen; an axis keyword (x, y, z) or three numbers giving an axis vector, followed by an angle, rotates in 3D.

Syntaxnone | <angle> | [ x | y | z | <number>{3} ] && <angle>
Initialnone
Applies toTransformable elements
InheritedNo
AnimationAs SLERP (spherical interpolation); none is treated as no rotation
SupportChrome 104 · Firefox 72 · Safari 14.1
Speccss-transforms-2
rotate: y 180deg;
Flip a box around its vertical axis.

scale

Scales a box. One value scales both x and y equally; two scale x and y separately; a third scales z.

Syntaxnone | [ <number> | <percentage> ]{1,3}
Initialnone
Applies toTransformable elements
InheritedNo
AnimationBy computed value; none is treated as no scaling
SupportChrome 104 · Firefox 72 · Safari 14.1
Speccss-transforms-2

A percentage is the same as the matching number: scale: 150% equals scale: 1.5. A negative value mirrors the box in that axis.

3D

perspective

Gives an element's children a 3D viewing distance, so their 3D transforms show depth: things further away look smaller. Smaller lengths give a stronger, closer effect.

Syntaxnone | <length [0,∞]>
Initialnone
Applies toTransformable elements
InheritedNo
AnimationBy computed value
SupportChrome 36 · Firefox 16 · Safari 9
Speccss-transforms-2

The property affects the element's children, all seen from one shared viewpoint. The perspective() transform function affects only the element it is applied to.

perspective-origin

Where the viewer stands when looking at the 3D children of an element with perspective: the vanishing point. It takes a position like background-position.

Syntax<position>
Initial50% 50%
Applies toTransformable elements
InheritedNo
PercentagesRefer to the size of the reference box
AnimationBy computed value
SupportChrome 36 · Firefox 16 · Safari 9
Speccss-transforms-2

transform-style

Whether an element's children share its 3D space (preserve-3d) or are flattened into its plane (flat). Use preserve-3d to build objects such as a cube from several faces.

Syntaxflat | preserve-3d
Initialflat
Applies toTransformable elements
InheritedNo
AnimationDiscrete
SupportChrome 36 · Firefox 16 · Safari 9
Speccss-transforms-2

Some properties force a flat result even when preserve-3d is set, because they need the element painted as one group first. Examples are opacity below 1, filter and overflow: hidden.

backface-visibility

Whether the back of a box shows when it is turned away from the viewer. Set hidden on both faces of a flip card so only the side facing the viewer is seen.

Syntaxvisible | hidden
Initialvisible
Applies toTransformable elements
InheritedNo
AnimationDiscrete
SupportChrome 36 · Firefox 16 · Safari 15.4
Speccss-transforms-2
.card { perspective: 800px; }
.card-inner { transform-style: preserve-3d; transition: rotate 0.5s; }
.card:hover .card-inner { rotate: y 180deg; }
.front, .back { backface-visibility: hidden; }
.back { rotate: y 180deg; }
A flip card: the two faces sit back to back, and each hides when turned away.

Motion path

offset

Shorthand that places a box on a path: the path's start position, the path, how far along it the box sits and which way it faces, then after a slash the point of the box that sits on the path.

Syntax[ <'offset-position'>? [ <'offset-path'> [ <'offset-distance'> || <'offset-rotate'> ]? ]? ]! [ / <'offset-anchor'> ]?
InitialSee individual properties
Applies toTransformable elements
InheritedSee individual properties
PercentagesSee individual properties
AnimationSee individual properties
SupportChrome 55 · Firefox 72 · Safari 16
Specmotion-1

The ! after the first group means that group must not be empty: at least one of its parts has to be given. The motion path is applied as a transform, before the transform property and after the individual transform properties.

@keyframes along { to { offset-distance: 100%; } }
.dot {
  offset: path('M 0 0 C 100 0 100 100 200 100') 0% auto;
  animation: along 2s ease-in-out infinite alternate;
}
Move a dot back and forth along a curve, turning to follow it.

offset-path

The path a box is placed on. An <offset-path> is a ray(), a url() pointing at an SVG shape, or a basic shape such as path(), circle() or inset(). The optional <coord-box> sets the box that a basic shape is sized against.

Syntaxnone | <offset-path> || <coord-box>
Initialnone
Applies toTransformable elements
InheritedNo
AnimationBy computed value
SupportChrome 55 · Firefox 72 · Safari 15.4
Specmotion-1

offset-distance

How far along the path the box sits. Animate it from 0% to 100% to move a box from the start of the path to the end.

Syntax<length-percentage>
Initial0
Applies toTransformable elements
InheritedNo
PercentagesRelative to the length of the offset path
AnimationBy computed value
SupportChrome 55 · Firefox 72 · Safari 16
Specmotion-1

offset-rotate

Which way the box faces as it sits on the path. auto turns it to follow the direction of the path, reverse turns it the opposite way, and an angle adds a fixed rotation, on its own or on top of auto or reverse.

Syntax[ auto | reverse ] || <angle>
Initialauto
Applies toTransformable elements
InheritedNo
AnimationBy computed value
SupportChrome 56 · Firefox 72 · Safari 16
Specmotion-1

A bare angle such as 0deg keeps the box upright whichever way the path turns.

offset-anchor

The point of the box that is placed on the path. auto uses the transform-origin point, which is the centre by default.

Syntaxauto | <position>
Initialauto
Applies toTransformable elements
InheritedNo
PercentagesRelative to the width and height of the element's reference box
AnimationBy computed value
SupportChrome 116 · Firefox 72 · Safari 16
Specmotion-1

offset-position

The starting point of a path that has no start of its own, such as a ray(). auto starts from the box's own position; normal starts from the centre of the containing block; a position places it in the containing block.

Syntaxnormal | auto | <position>
Initialnormal
Applies toTransformable elements
InheritedNo
PercentagesRefer to the size of the containing block
AnimationBy computed value
SupportChrome 116 · Firefox 122 · Safari 16
Specmotion-1