ā¤ Like
šŸ”– Save
šŸ”— Share
@thedevspaceio
@thedevspaceio

CSS Transforms Cheatsheet

CSS Transforms Cheatsheet

CSS transforms allow you to visually manipulate an element by skewing, rotating, translating, or scaling it. You can combine multiple transforms for powerful effects.

Common Transform Functions

FunctionDescription
translateXMoves the element along the X axis.
translateYMoves the element along the Y axis.
translateMoves the element along both X and Y axes.
scaleScales the element uniformly on both axes.
scaleXScales the element along the X axis.
scaleYScales the element along the Y axis.
rotateRotates the element around its origin.
skewXSkews (shears) the element along the X axis.
skewYSkews (shears) the element along the Y axis.
skewSkews the element along one or both axes.
matrixApplies a 2D transformation defined by a matrix.

translateX()

Moves an element along the X axis. Accepts lengths or percentages. Percentages are relative to the element's own size.

Positive values move right, negative values move left.

css
div {
  transform: translateX(50px);
}

transform: translateX(50px)

transform: translateX(-50px)

transform: translateX(100%)

transform: translateX(-25%)

translateY()

Moves an element along the Y axis. Accepts lengths or percentages. Positive values move down, negative values move up.

transform: translateY(-20px)

transform: translateY(50px)

transform: translateY(100%)

translate()

Moves an element in both X and Y axes. Accepts one or two values.

transform: translate(30px, 20px)

transform: translate(50px)

scale()

Scales an element uniformly in both X and Y directions.

transform: scale(1.2)

scaleX()

Scales an element only on the X axis.

transform: scaleX(2)

scaleY()

Scales an element only on the Y axis.

transform: scaleY(0.5)

rotate()

Rotates an element around the transform origin.

transform: rotate(45deg)

skewX()

Skews an element along the X axis.

transform: skewX(20deg)

skewY()

Skews an element along the Y axis.

transform: skewY(-10deg)

skew()

Skews an element along both axes.

transform: skew(20deg, 10deg)

matrix()

Applies a custom 2D matrix transform.

transform: matrix(1, 0, 0, 1, 30, 20)

Notes

  • Transforms do not affect the document flow (the space taken by the element).
  • Use transform-origin to change the point around which transforms are applied (default is the element's center).
  • Transforms can be animated with CSS transitions or keyframes for smooth effects.