CSS rotate Property

The CSS rotate property rotates an element around a specified axis without requiring the transform property.

It is an individual transform property that supports two-dimensional and three-dimensional rotation. You can specify an angle, choose a rotation axis, change the rotation origin, and animate rotation independently of other transforms such as translation and scaling.

rotate Syntax

The rotate property accepts none, an angle, an axis keyword followed by an angle, or three numbers defining a rotation axis followed by an angle.

Basic Syntax

selector {
  rotate: 45deg;
}

Available Values

.element {
  rotate: none;
}
.element {
  rotate: 45deg;
}
.element {
  rotate: -30deg;
}
.element {
  rotate: 0.25turn;
}
.element {
  rotate: x 45deg;
}
.element {
  rotate: y 60deg;
}
.element {
  rotate: z 90deg;
}
.element {
  rotate: 1 1 0 45deg;
}

CSS-Wide Keywords

.element {
  rotate: initial;
}
.element {
  rotate: inherit;
}
.element {
  rotate: unset;
}
.element {
  rotate: revert;
}
.element {
  rotate: revert-layer;
}

When only an angle is specified, the element rotates around the z-axis, which produces a two-dimensional rotation in the plane of the screen.

Property Values

Value Description
none Specifies no individual rotation transform. This is the initial value.
<angle> Rotates the element around the z-axis using an angle such as 45deg or 0.5turn.
x <angle> Rotates the element around the x-axis.
y <angle> Rotates the element around the y-axis.
z <angle> Rotates the element around the z-axis.
<number> <number> <number> <angle> Defines a three-dimensional rotation axis using an x, y, and z vector followed by the rotation angle.
initial Resets the property to none.
inherit Uses the computed value from the parent element.
unset Resets the property to none because it is not inherited.
revert Reverts the property according to CSS cascade origin rules.
revert-layer Reverts the property according to CSS cascade layer rules.

Property Characteristics

Characteristic Value
Initial value none
Inherited No
Applies to Transformable elements
Computed value Keyword none or a rotation axis and angle
Animation type By computed value, using rotation interpolation
Percentages Not applicable

Valid Values

.icon {
  rotate: 30deg;
}
.card {
  rotate: -15deg;
}
.panel {
  rotate: y 45deg;
}
.shape {
  rotate: 1 0 1 60deg;
}

Invalid Values

.element {
  rotate: 45;
}
.element {
  rotate: 50%;
}
.element {
  rotate: clockwise;
}
.element {
  rotate: 20px;
}
.element {
  rotate: x y 45deg;
}

Rotation angles require a valid angle unit. The property does not accept percentages, lengths, arbitrary direction keywords, or multiple axis keywords in the same value.

How It Works

The rotate property applies a geometric rotation to an element around a rotation axis passing through its transform origin.

Unlike ordinary layout properties, rotation changes the element's visual presentation without changing the space originally allocated to it in normal document flow.

Step 1: Define the Element

.box {
  width: 120px;
  height: 120px;
  background-color: #2563eb;
}

Step 2: Apply a Rotation

.box {
  rotate: 30deg;
}

The box rotates 30 degrees around its default transform origin, which is normally its center.

Step 3: Change the Rotation Origin

.box {
  transform-origin: top left;
}

The box now rotates around its top-left corner instead of its center.

Complete Example

.box {
  width: 120px;
  height: 120px;
  background-color: #2563eb;
  rotate: 30deg;
  transform-origin: center;
}

Important Distinction

The rotate property changes an element's visual orientation. It does not change the element's original position in normal document flow or automatically reposition surrounding elements.

Two-Dimensional Rotation

Two-dimensional rotation turns an element clockwise or counterclockwise in the plane of the screen.

Clockwise Rotation

.box {
  rotate: 45deg;
}

In a typical left-to-right writing direction, a positive angle rotates the element clockwise.

Counterclockwise Rotation

.box {
  rotate: -45deg;
}

In a typical left-to-right writing direction, a negative angle rotates the element counterclockwise.

Quarter Turn

.box {
  rotate: 90deg;
}

Half Turn

.box {
  rotate: 180deg;
}

Full Turn

.box {
  rotate: 360deg;
}

A full turn returns the element to its original visual orientation, although the rotation value remains specified and can be used in animations.

Rotation and Writing Direction

For two-dimensional rotations, the visual direction of positive angles depends on the writing direction. In right-to-left contexts, positive angles rotate counterclockwise rather than clockwise.

Important Consideration

Rotating an element does not automatically change its layout dimensions. A rotated rectangle may extend beyond the area originally reserved for it.

Three-Dimensional Rotation

The rotate property also supports three-dimensional rotation around the x-axis, y-axis, z-axis, or a custom axis.

Rotation Around the X-Axis

.card {
  rotate: x 45deg;
}

The element rotates around a horizontal axis running through its transform origin.

Rotation Around the Y-Axis

.card {
  rotate: y 45deg;
}

The element rotates around a vertical axis running through its transform origin.

Rotation Around the Z-Axis

.card {
  rotate: z 45deg;
}

The element rotates within the plane of the screen, producing a two-dimensional visual effect.

Custom Rotation Axis

.card {
  rotate: 1 1 0 45deg;
}

The three numbers define a vector with x, y, and z components. The browser uses this vector to determine the rotation axis.

Using Perspective

.scene {
  perspective: 600px;
}
.scene .card {
  rotate: y 45deg;
}

Perspective makes three-dimensional rotation appear more realistic by creating depth and foreshortening.

Using transform-style

.scene {
  perspective: 600px;
}
.scene .group {
  transform-style: preserve-3d;
}
.scene .card {
  rotate: x 30deg;
}

The transform-style: preserve-3d declaration allows eligible descendants to participate in a shared three-dimensional rendering space.

Important Consideration

Three-dimensional rotation can make content difficult to read when the element turns away from the viewer. Use perspective and rotation angles carefully, especially for text and interactive controls.

Rotation Angle Units

The rotate property accepts standard CSS angle units, including degrees, radians, gradians, and turns.

Unit Description Full Rotation
deg Degrees 360deg
rad Radians Approximately 6.283185rad
grad Gradians 400grad
turn Complete turns 1turn

Using Degrees

.box {
  rotate: 90deg;
}

Using Radians

.box {
  rotate: 1.570796rad;
}

Using Gradians

.box {
  rotate: 100grad;
}

Using Turns

.box {
  rotate: 0.25turn;
}

These four examples represent approximately the same quarter-turn rotation.

Using calc()

.box {
  rotate: calc(45deg + 15deg);
}

The calc() function can combine compatible angle values.

Important Consideration

Use deg for familiar degree measurements and turn when expressing fractions or multiples of a complete rotation.

Changing the Rotation Origin

The transform-origin property determines the point around which an element rotates.

For many HTML elements, the default origin is the center of the element.

Rotate Around the Center

.box {
  rotate: 45deg;
  transform-origin: center;
}

Rotate Around the Top-Left Corner

.box {
  rotate: 45deg;
  transform-origin: top left;
}

Rotate Around the Bottom-Right Corner

.box {
  rotate: 45deg;
  transform-origin: bottom right;
}

Using Percentage Coordinates

.box {
  rotate: 45deg;
  transform-origin: 25% 75%;
}

The rotation origin is positioned 25% across the element and 75% down from its top edge.

Using Length Values

.box {
  rotate: 45deg;
  transform-origin: 20px 30px;
}

Three-Dimensional Transform Origin

.box {
  rotate: y 45deg;
  transform-origin: center center 40px;
}

The third value specifies an offset along the z-axis.

Important Consideration

Changing the transform origin affects the visual path of rotation, but it does not change the element's original layout position.

rotate Versus transform

The rotate property is an individual transform property. The transform property can combine multiple transform functions in a single declaration.

Using rotate

.box {
  rotate: 45deg;
}

Using transform

.box {
  transform: rotate(45deg);
}

Both declarations can produce the same visual rotation when no other transforms are applied.

Combining Individual Transform Properties

.box {
  translate: 30px 10px;
  rotate: 45deg;
  scale: 1.2;
}

Individual transform properties can be declared and animated independently.

Combining rotate With transform

.box {
  rotate: 30deg;
  transform: translateX(40px);
}

Both transformations apply. The individual transform properties are composed before the transformations specified by transform.

Transform Order

Individual transforms are applied in a defined order: translation, rotation, scaling, and then the transform property. This order can produce different results from listing transform functions in another sequence.

When to Use rotate

Use rotate when rotation should be controlled independently, particularly for animations and interactive effects.

When to Use transform

Use transform when a specific sequence of transform functions is required or when supporting older browsers that do not implement individual transform properties.

Animating Rotation

The rotate property can be animated using CSS transitions and keyframe animations.

Hover Rotation

.icon {
  rotate: 0deg;
  transition: rotate 0.3s ease;
}
.icon:hover {
  rotate: 45deg;
}

The icon rotates smoothly when the pointer moves over it.

Continuous Rotation

.spinner {
  animation: spin 2s linear infinite;
}
@keyframes spin {
  from {
    rotate: 0deg;
  }
  to {
    rotate: 360deg;
  }
}

The element completes one full rotation every two seconds.

Three-Dimensional Rotation Animation

.card {
  animation: card-turn 3s ease-in-out infinite alternate;
}
@keyframes card-turn {
  from {
    rotate: y 0deg;
  }
  to {
    rotate: y 180deg;
  }
}

Respecting Reduced Motion Preferences

@media (prefers-reduced-motion: reduce) {
  .spinner,
  .card {
    animation: none;
    transition: none;
  }
}

This disables the animations for users who request reduced motion.

Important Consideration

Continuous or rapid rotation can be distracting or uncomfortable for some users. Keep motion purposeful and provide reduced-motion alternatives.

rotate Example

The following example demonstrates positive, negative, and three-dimensional rotation using the rotate property.

HTML Example

<div class="rotate-demo">
  <div class="rotate-item rotate-positive">30deg</div>
  <div class="rotate-item rotate-negative">-30deg</div>
  <div class="rotate-item rotate-three-d">y 45deg</div>
</div>

CSS Example

.rotate-demo {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-around;
  align-items: center;
  gap: 30px;
  padding: 45px 20px;
  perspective: 600px;
}
.rotate-demo .rotate-item {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 110px;
  height: 80px;
  padding: 10px;
  background-color: #2563eb;
  color: #ffffff;
  font-weight: bold;
  text-align: center;
  box-sizing: border-box;
}
.rotate-demo .rotate-positive {
  rotate: 30deg;
}
.rotate-demo .rotate-negative {
  rotate: -30deg;
}
.rotate-demo .rotate-three-d {
  rotate: y 45deg;
}
Browser Result
30deg
-30deg
y 45deg

In a typical left-to-right writing direction, the first box rotates clockwise, the second rotates counterclockwise, and the third rotates around its vertical y-axis.

Changing the Rotation Origin

.rotate-demo .rotate-positive {
  transform-origin: top left;
}

The first box now rotates around its top-left corner.

Increasing the Three-Dimensional Rotation

.rotate-demo .rotate-three-d {
  rotate: y 70deg;
}

The third box turns farther away from the viewer, making its visible width appear smaller under perspective.

Accessibility Considerations

Rotated content should remain readable, accessible, and usable with different input methods and display settings.

Maintain Readable Text

Avoid excessive rotation of text, especially when it makes reading difficult or reduces legibility.

Respect Reduced Motion Preferences

Use the prefers-reduced-motion media query to limit or disable unnecessary rotation animations.

Preserve Keyboard Navigation

Rotation changes visual presentation but does not change the element's position in the keyboard focus order.

Avoid Overlapping Content

Rotated elements may extend beyond their original layout boxes. Ensure they do not obscure important text or controls.

Maintain Visible Focus Indicators

Interactive rotated elements should retain clearly visible focus indicators.

Use Three-Dimensional Effects Carefully

Large three-dimensional rotations can make text difficult to read or temporarily hide controls from view.

Important Consideration

The rotate property affects visual presentation only. It does not change the semantic meaning, reading order, or accessibility relationships of an element.

Common Mistakes

Omitting the Angle Unit

.box {
  rotate: 45;
}

Nonzero rotation angles require a valid angle unit, such as deg, rad, grad, or turn.

Using Percentage Values

.box {
  rotate: 50%;
}

Percentages are not valid rotation angles.

Confusing rotate With the rotate() Function

.box {
  rotate: rotate(45deg);
}

The rotate property accepts an angle directly. The rotate() function is used with the transform property.

Expecting Rotation to Change Layout Space

Rotating an element does not cause surrounding elements to automatically reposition around its rotated shape.

Ignoring the Transform Origin

Elements rotate around their transform origin, which is normally the center for many HTML elements. Change transform-origin when another pivot point is required.

Assuming All Transform Orders Are Equivalent

Individual transform properties follow a defined composition order. Combining them with transform can produce different results from rearranging transform functions.

Using Excessive Three-Dimensional Rotation

Large rotations around the x-axis or y-axis can make content difficult to see or interact with.

Ignoring Reduced Motion Preferences

Continuous rotation animations should provide an appropriate reduced-motion alternative.

Important Considerations

Keep the following points in mind when using rotate:

  • It is an individual CSS transform property.
  • Its initial value is none.
  • The property is not inherited.
  • It applies to transformable elements.
  • An angle without an axis specifies rotation around the z-axis.
  • The x, y, and z keywords specify rotation axes.
  • Three numeric components can define a custom three-dimensional rotation axis.
  • Supported angle units include deg, rad, grad, and turn.
  • Nonzero angles require a valid angle unit.
  • Negative rotation angles are permitted.
  • Two-dimensional rotation direction depends on writing direction.
  • The transform-origin property controls the pivot point.
  • For many HTML elements, the default transform origin is the center.
  • Rotation changes visual presentation without changing normal layout space.
  • Rotated elements can overlap nearby content.
  • Three-dimensional rotation can be combined with perspective.
  • The perspective property creates a depth effect for three-dimensional transforms.
  • The transform-style property controls how eligible descendants participate in three-dimensional rendering.
  • Individual transform properties can be animated independently.
  • Translation, rotation, scaling, and the transform property follow a defined composition order.
  • Using rotate does not prevent additional transforms from being applied.
  • The rotate() function is used inside the transform property.
  • Rotation animations can use transitions or keyframes.
  • Respect reduced-motion preferences when animating rotation.
  • Ensure rotated content remains readable and accessible.
  • Test three-dimensional effects in different browsers and viewport sizes.

Browser Support

The CSS rotate property is Baseline Widely available and is supported in current versions of major browsers.

The individual rotate property is newer than the rotate() transform function. Older browsers may support transform: rotate() without supporting the standalone rotate property.

For current compatibility information, visit Can I Use? and search for rotate.

For older browser compatibility, consider using transform: rotate() as a fallback where appropriate.

Specifications

The rotate property is defined in CSS Transforms Module Level 2.

CSS Transforms Module Level 2

The specification defines individual transform properties, rotation axes, angle interpolation, and how individual transforms are composed with the transform property.

For additional documentation and examples, consult MDN Web Docs.

MDN Web Docs: rotate