Codectionary / Developer documentation / CSS

Transforms

transform lets you visually move, rotate, scale, or skew an element without affecting the document flow of surrounding elements - unlike changing position/width directly. Multiple transform functions can be combined in a single declaration, and transform-origin controls the pivot point for rotation and scaling.

Syntax

transform: translate() rotate() scale() skew();

Examples

The Four Core Transform Functions

Moving, rotating, scaling, and skewing an element.

.move { transform: translate(20px, 10px); }
.rotate { transform: rotate(15deg); }
.grow { transform: scale(1.2); }
.skewed { transform: skew(-10deg, 0); }

/* Combining multiple transforms in one declaration */
.combined { transform: translateX(10px) rotate(5deg) scale(1.1); }

transform-origin

Controlling the pivot point that rotation and scaling happen around.

.default-origin {
  transform: rotate(45deg); /* pivots around the center by default */
}

.corner-origin {
  transform-origin: top left;
  transform: rotate(45deg); /* now pivots around the top-left corner instead */
}

Parameters and values

  • translate() (x, y): Moves the element without affecting document flow
  • rotate() (angle): Rotates the element around its transform-origin
  • scale() (x, y): Resizes the element proportionally or per-axis
  • transform-origin (position): Sets the pivot point for rotation and scaling

Best practices

  • Use transform: translate() instead of changing top/left for moving elements - transforms are GPU-accelerated and do not trigger layout recalculation
  • Combine multiple transform functions in a single declaration rather than stacking multiple transform properties, since only the last one would apply
  • Use scale() for hover effects instead of changing width/height directly, for smoother performance
  • Remember transformed elements do not affect the layout of surrounding elements - the space they originally occupied stays reserved

At a glance

Purpose
Presentation and layout
File extension
.css
Runs in
Web browsers
Usually used with
HTML and JavaScript

Specifications & further reading

Related CSS documentation