CSS propertyTransforms

transform-origin

Sets the point an element rotates around and scales from.

Initial value
50% 50% 0
Inherited
No
Animatable
yes, as a length or percentage
Applies to
transformable elements
JavaScript
element.style.transformOrigin = "top left"
On this page

Example

#
CSS
.progress-bar {
  transform: scaleX(0.7);
  transform-origin: left;
}
Preview

Definition and usage

#

The transform-origin property sets the centre of a transform. By default it is the centre of the element, so rotation spins the element around its centre and scaling enlarges it evenly in all directions.

Moving the point to a corner completely changes the effect: rotating around the top left corner works like a door opening on a hinge, and scaling from the bottom makes the element grow upwards.

It accepts keywords (top, left, center…), percentages, and lengths. The third value sets the offset along the Z axis for 3D transforms.

Syntax

#
Syntax
transform-origin: <x> <y>? <z>?;

Values

#
  • center

    Rotation around the centre of the element.
  • top left

    Rotation around the top left corner.
  • bottom right

    Rotation around the bottom right corner.
  • 50% 150%

    outside the element

    The pivot point is below the element, like a pendulum.

Values in practice

#

center

Rotation around the centre of the element.
.demo { transform-origin: center; }

top left

Rotation around the top left corner.
.demo { transform-origin: top left; }

bottom right

Rotation around the bottom right corner.
.demo { transform-origin: bottom right; }

50% 150%

The pivot point is below the element, like a pendulum.
.demo { transform-origin: 50% 150%; }

Browser support

#

Widely available

Works in all modern browsers, phones included. You can use it without worry.

  • Chrome
  • Edge
  • Firefox
  • Safari

Good practices

#
  • Progress bars animated with scaleX() need transform-origin: left, otherwise they grow from the centre.
  • Dropdown menus look more natural when they scale from the point they emerge from, for example top right.

Related entries

#

Practise it in lessons

#

Spotted a mistake or missing an example? Write to us.