Support0

CSS transform playground

Compose 2D and 3D transforms, compare how function order changes the result, and move the origin before copying the generated code.

Ask AI

CSS transform playground

Response generated with openai/gpt-5.4-nano. AI can make mistakes. Always review the result.
Transform space

The dashed outline preserves the untransformed reference.

2D
HTML
<div class="transform-demo">
  CSS transform
</div>
Tailwind CSS
Examples for Tailwind CSS 4.3 with the default theme. Custom values keep arbitrary classes when there is no equivalent utility. Changing the theme can change utility values.
<div class="inline-[250px] block-[250px] grid place-items-center rounded-2xl bg-linear-to-br from-orange-500 to-blue-600 text-slate-50 transform-[translate(32px,_-18px)_rotate(-12deg)_scale(1.05,_1.05)_skew(0deg,_0deg)] origin-center">
  CSS transform
</div>
CSS
.transform-demo {
  inline-size: 250px;
  block-size: 250px;
  background: linear-gradient(135deg, #f97316, #2563eb);
  display: grid;
  place-items: center;
  border-radius: 1rem;
  color: #f8fafc;
  transform: translate(32px, -18px) rotate(-12deg) scale(1.05, 1.05) skew(0deg, 0deg);
  transform-origin: 50% 50%;
}

Educational guide to transform

Transform coordinates, keep the space in the layout

Understand function order, origin, and depth. Compare real results and distinguish visual changes from their effects on flow and stacking.

Mental model

The browser first calculates the box in the layout, then transforms its coordinate system for painting.

  1. Reference box

    Its size provides a reference for percentages and the origin.

  2. Origin and axes

    Each operation composes a new coordinate system.

  3. Visual result

    The box changes appearance; its neighbors keep the space from the layout.

Layout → coordinates → paintingConceptual model. The following samples apply native CSS; the dashed outline marks the untransformed box.

translate moves; rotate turns; scale resizes and skew shears the axes. Separate functions in a list with spaces, not commas between functions. none is the initial value. A non-replaced inline, such as a text span, needs a transformable box: for example, display: inline-block.

In these LTR HTML samples, positive X points right, positive Y down, and positive Z toward the viewer. translateX(50%) uses the width of the element’s own reference box; translateY(50%), its height. These are not percentages of the parent. These samples use the border box; transform-box can select a different reference and is especially relevant in SVG.

Order changes the result

The same functions and values can end up in different positions.

Read the list from left to right as successive coordinate changes: A translates the system and then rotates it; B rotates the system, so the translation follows its already rotated X axis. An equivalent reading keeps the parent’s axes fixed and applies the operations to the point from right to left. Do not mix the two readings as though they were a timeline.

Translate and rotate versus rotate and translate

A · translateX(2rem) rotate(30deg)
A →
B · rotate(30deg) translateX(2rem)
B →
A moves 2rem horizontally. B moves along an axis rotated by 30 degrees, so it also moves down. Both keep the same rotation and dashed reference.
Translate and rotate versus rotate and translate
<div class="transform-scene-order">
  <figure>
    <figcaption>A · translateX(2rem) rotate(30deg)</figcaption>
    <div class="stage">
      <div class="reference"><div class="tile a">A →</div></div>
    </div>
  </figure>
  <figure>
    <figcaption>B · rotate(30deg) translateX(2rem)</figcaption>
    <div class="stage">
      <div class="reference"><div class="tile b">B →</div></div>
    </div>
  </figure>
</div>
:root {
  color-scheme: light dark;
}

.transform-scene-order {

  display: grid;
  gap: 2rem;
  min-inline-size: 0;

  .stage {
    display: grid;
    place-items: center;
    padding-block: 3rem;
  }

  .reference {
    inline-size: min(5rem, 25%);
    block-size: 4rem;
    outline: 2px dashed currentColor;
  }

  .tile {
    display: grid;
    place-items: center;
    box-sizing: border-box;
    inline-size: 100%;
    block-size: 100%;
    border: 2px solid currentColor;
    background: light-dark(oklch(0.87 0.1 261), oklch(0.78 0.24 261));
    color: light-dark(oklch(0.2 0.01 95), oklch(0.12 0.01 260));
    font-size: 1rem;
  }

  figure {
    min-inline-size: 0;
    margin: 0;
  }

  figcaption {
    overflow-wrap: anywhere;
  }

  .a {
    transform: translateX(2rem) rotate(30deg);
  }

  .b {
    transform: rotate(30deg) translateX(2rem);
  }
}

The cascade does not concatenate lists: a new transform declaration replaces the previous one. To change just a rotation, repeat the full composition or use individual properties. scale(2) before translateX(2rem) also scales the displacement; a negative scale mirrors the axis, and a zero scale can make the box disappear.

The origin is the pivot

Changing the pivot changes the visible position without changing the angle.

On a typical HTML box, transform-origin: 50% 50% places the pivot at its center. left top equals 0% 0%. The origin does not place the box in a corner of its parent: it sets the reference around which the transform is composed. You can use lengths and percentages outside 0–100%; a third Z value must be a length, not a percentage.

Center versus top left corner

A · transform-origin: 50% 50%
A →
B · transform-origin: left top
B →
Both boxes rotate 30 degrees. A turns around its center; B keeps its top left corner as the pivot, marked by the start of the dashed outline.
Center versus top left corner
<div class="transform-scene-origin">
  <figure>
    <figcaption>A · transform-origin: 50% 50%</figcaption>
    <div class="stage">
      <div class="reference"><div class="tile a">A →</div></div>
    </div>
  </figure>
  <figure>
    <figcaption>B · transform-origin: left top</figcaption>
    <div class="stage">
      <div class="reference"><div class="tile b">B →</div></div>
    </div>
  </figure>
</div>
:root {
  color-scheme: light dark;
}

.transform-scene-origin {

  display: grid;
  gap: 2rem;
  min-inline-size: 0;

  .stage {
    display: grid;
    place-items: center;
    padding-block: 3rem;
  }

  .reference {
    inline-size: min(5rem, 25%);
    block-size: 4rem;
    outline: 2px dashed currentColor;
  }

  .tile {
    display: grid;
    place-items: center;
    box-sizing: border-box;
    inline-size: 100%;
    block-size: 100%;
    border: 2px solid currentColor;
    background: light-dark(oklch(0.87 0.1 261), oklch(0.78 0.24 261));
    color: light-dark(oklch(0.2 0.01 95), oklch(0.12 0.01 260));
    font-size: 1rem;
  }

  figure {
    min-inline-size: 0;
    margin: 0;
  }

  figcaption {
    overflow-wrap: anywhere;
  }

  .tile {
    transform: rotate(30deg);
  }

  .a {
    transform-origin: 50% 50%;
  }

  .b {
    transform-origin: left top;
  }
}

The origin affects rotation and scaling; moving it does not change a standalone translation. In SVG, the initial value and reference box can differ: check transform-box and transform-origin before reusing an HTML recipe.

Flow, overflow, and stacking

Moving the painting does not rearrange siblings or remove the original space.

The outline keeps the first box’s space. Its content moves toward the second, which stays in the same layout position. To separate elements, use gap, margin, or layout itself. A transform can extend the scrollable area; overflow: hidden can clip content or focus and does not fix the cause of an overlap.

The neighbor does not move aside

This box moves down 1.5rem.

This box keeps its place.

The first box moves down 1.5rem and overlaps the next. The dashed space stays above; both texts explain what moved and what keeps its place.
The neighbor does not move aside
<div class="transform-scene-flow">
  <div class="slot"><p class="shifted">This box moves down 1.5rem.</p></div>
  <p class="next">This box keeps its place.</p>
</div>
:root {
  color-scheme: light dark;
}

.transform-scene-flow {
  display: grid;
  gap: 0.5rem;
  padding-block-end: 1.5rem;

  .slot {
    outline: 2px dashed currentColor;
  }

  p {
    margin: 0;
    padding: 1rem;
    border: 2px solid currentColor;
    overflow-wrap: anywhere;
  }

  .shifted {
    transform: translateY(1.5rem);
    background: light-dark(oklch(0.87 0.1 261), oklch(0.78 0.24 261));
    color: light-dark(oklch(0.2 0.01 95), oklch(0.12 0.01 260));
  }

  .next {
    border-style: dashed;
  }
}

A transform other than none, even translate(0), creates a stacking context and a containing block for absolute and fixed descendants. A fixed element can become tied to that ancestor instead of the viewport. A child’s z-index is resolved within the context: increasing it does not let it escape above all of the ancestor’s siblings. These effects apply even when the transform is visually neutral.

Individual properties and composition

Change one transform without rewriting the others.

translate, rotate, and scale are independent properties. Their composition order is always translate → rotate → scale → transform, even if you reorder the declarations. For a different sequence, use a transform list. They accumulate with it: scale: 2 alongside transform: scale(3) produces a scale of 6, not 3.

Scaling while keeping translation and rotation

A →
Toggle the checkbox with a click or Space. Only scale changes from 1 to 1.25; translate and rotate keep their values. The change is immediate, without animation or JavaScript.
Scaling while keeping translation and rotation
<div class="transform-scene-individual">
  <label><input type="checkbox" /> Enlarge with scale: 1.25</label>
  <div class="stage">
    <div class="reference"><div class="tile">A →</div></div>
  </div>
</div>
:root {
  color-scheme: light dark;
}

.transform-scene-individual {

  display: grid;
  gap: 2rem;
  min-inline-size: 0;

  .stage {
    display: grid;
    place-items: center;
    padding-block: 3rem;
  }

  .reference {
    inline-size: min(5rem, 25%);
    block-size: 4rem;
    outline: 2px dashed currentColor;
  }

  .tile {
    display: grid;
    place-items: center;
    box-sizing: border-box;
    inline-size: 100%;
    block-size: 100%;
    border: 2px solid currentColor;
    background: light-dark(oklch(0.87 0.1 261), oklch(0.78 0.24 261));
    color: light-dark(oklch(0.2 0.01 95), oklch(0.12 0.01 260));
    font-size: 1rem;
  }

  label {
    overflow-wrap: anywhere;
  }

  input:focus-visible {
    outline: 3px solid light-dark(oklch(0.46 0.14 261), oklch(0.82 0.18 261));
    outline-offset: 3px;
  }

  .tile {
    translate: 1rem 0;
    rotate: -15deg;
    scale: 1;
  }

  &:has(input:checked) .tile {
    scale: 1.25;
  }
}

The base declares scale: 1 to keep the context before and after the change. Identity values of these properties can also create a stacking context and containing block; none is not equivalent to an identity in these effects. Avoid applying identities globally as a supposed performance fix.

Depth and perspective

Rotating in 3D and projecting with perspective are different decisions.

rotateX() and rotateY() tilt the plane; translateZ() changes its depth. The perspective() function inside transform adds projection to the element itself, and its position in the list matters. Here it comes before the rotation. A smaller positive distance strengthens perspective; a larger distance softens it. Do not confuse Z depth with z-index.

The same rotation, with and without perspective

A · rotateY(45deg)
A →
B · perspective(16rem) rotateY(45deg)
B →
A uses rotateY(45deg) without perspective. B adds perspective(16rem): sides at different depths project at different sizes. Both are static samples of a flat surface.
The same rotation, with and without perspective
<div class="transform-scene-depth">
  <figure>
    <figcaption>A · rotateY(45deg)</figcaption>
    <div class="stage">
      <div class="reference"><div class="tile a">A →</div></div>
    </div>
  </figure>
  <figure>
    <figcaption>B · perspective(16rem) rotateY(45deg)</figcaption>
    <div class="stage">
      <div class="reference"><div class="tile b">B →</div></div>
    </div>
  </figure>
</div>
:root {
  color-scheme: light dark;
}

.transform-scene-depth {

  display: grid;
  gap: 2rem;
  min-inline-size: 0;

  .stage {
    display: grid;
    place-items: center;
    padding-block: 3rem;
  }

  .reference {
    inline-size: min(5rem, 25%);
    block-size: 4rem;
    outline: 2px dashed currentColor;
  }

  .tile {
    display: grid;
    place-items: center;
    box-sizing: border-box;
    inline-size: 100%;
    block-size: 100%;
    border: 2px solid currentColor;
    background: light-dark(oklch(0.87 0.1 261), oklch(0.78 0.24 261));
    color: light-dark(oklch(0.2 0.01 95), oklch(0.12 0.01 260));
    font-size: 1rem;
  }

  figure {
    min-inline-size: 0;
    margin: 0;
  }

  figcaption {
    overflow-wrap: anywhere;
  }

  .a {
    transform: rotateY(45deg);
  }

  .b {
    transform: perspective(16rem) rotateY(45deg);
  }
}

The perspective property on the parent gives its children a shared perspective; it is a different API from perspective() in each list. For a hierarchy that preserves depth between descendants, study transform-style: preserve-3d: it is not inherited, and grouping properties such as opacity below 1 can flatten the result. You do not need preserve-3d to tilt a single card.

Common mistakes

Check the box, composition, and context before adding another transform.

Translation disappears when rotating

Expected result
Add rotate while keeping an earlier translate.
Cause
Another transform declaration replaces the entire list.
Solution
Repeat the required functions or separate translate and rotate into individual properties.

50% is not half the container

Expected result
Move half the parent’s width with translateX(50%).
Cause
The percentage is calculated from the transformed element’s reference box.
Solution
Distinguish the element’s reference from its parent’s space; use Grid or Flexbox for layout alignment.

A fixed element stops following the viewport

Expected result
A viewport-fixed descendant inside a card.
Cause
The transformed card establishes its containing block, even with an identity.
Solution
Review the hierarchy and place the element outside that ancestor when it must depend on the viewport.

The box or its focus disappears

Expected result
Shrink or move a box without losing content or access.
Cause
A zero scale or a clipping ancestor can hide the painting; content may remain in the focus order.
Solution
Keep sufficient bounds and space; do not use transform to hide content semantically or replace layout.

Support and compatibility

Check every piece you plan to use and keep the experience readable without effects.

2D transforms, 3D transforms, and individual properties are Baseline Widely Available according to the consulted sources. This status does not certify every SVG combination, animation, or 3D scene. The cards separate the families; an individual property and its namesake function use different syntax.

These samples have no animations. If you add transitions to an interface, respect prefers-reduced-motion: reduce, keep information and focus available without motion, and avoid intense automatic scaling. Do not shrink text with scale instead of choosing a readable size, or force transform: translateZ(0) as a promise of acceleration.

For an older browser without individual properties, you can use an equivalent transform list, preserving order and origin and repeating it when changing state. Do not apply both paths at once or their effects will accumulate. An @supports query checks syntax, not visual quality or accessibility.