Menu
×
   ❮     
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS DSA TYPESCRIPT ANGULAR ANGULARJS GIT POSTGRESQL MONGODB ASP AI R GO KOTLIN SWIFT SASS VUE GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE INTRO TO PROGRAMMING INTRO TO HTML & CSS BASH RUST

HTML and CSS Transforms


HTML & CSS: Transforms

CSS transforms let you rotate, scale, skew, and translate elements without affecting the normal flow.

Combine them with transitions and animations for compelling interactions.


2D transforms

  • translate() - move along X or Y axes.
  • scale() - resize elements uniformly or per axis.
  • rotate() - spin elements by degrees or turns.
  • skew() - slant shapes for dynamic effects.

Note: X axis is horizontal, Y axis is vertical.

Positive values move right or down, negative values move left or up.

If you want to read more about CSS 2D Transforms or get an in-depth understanding, go to CSS 2D Transforms in our CSS tutorial.


Example: Interactive Cards

This example uses 3D transforms to tilt cards on hover/focus.

Perspective is set on the element to create depth, and transforms are applied on interaction.

Tilt on hover

<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="styles.css" type="text/css">
</head>
<body>
  <section class="grid">
    <article class="card" tabindex="0">Design tokens</article>
    <article class="card" tabindex="0">Accessibility audit</article>
    <article class="card" tabindex="0">Team workflows</article>
  </section>
</body>
</html>
.grid {
  display: grid;
  gap: 24px;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  padding: clamp(24px, 6vw, 80px);
}
.card {
  padding: 32px;
  border-radius: 24px;
  background: linear-gradient(145deg, #1e293b, #0f172a);
  color: #fff;
  transform: perspective(700px) rotateX(0deg) rotateY(0deg);
  transition: transform 220ms ease, box-shadow 220ms ease;
}
.card:hover,
.card:focus-visible {
  transform: perspective(700px) rotateX(6deg) rotateY(-6deg) translateY(-6px);
  box-shadow: 0 24px 40px rgba(15, 23, 42, 0.35);
}
Try it Yourself »

On interaction, the card tilts and lifts slightly, creating a dynamic feel.

The perspective and easing make the motion feel natural.



3D transforms

  • Enable 3D perspective on a parent: perspective: 800px;.
  • Use rotateX, rotateY, rotateZ, and translateZ.
  • Apply transform-style: preserve-3d; to keep child depth.

Note: Perspective controls how strong the 3D effect feels-the smaller the number, the more dramatic the depth.


Transform origin

  • Default origin is the element center.
  • Shift the anchor with transform-origin: top left; or percentages.
  • Useful for pivoting menus or scaling from a specific corner.

Performance tips

  • Transforms are GPU-accelerated; prefer them over changing top/left.
  • Avoid forcing layout by combining transforms with will-change when necessary.
  • Provide reduced-motion fallbacks for large movements.

Note: will-change is a performance hint that tells the browser which properties might animate soon.



×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
sales@w3schools.com

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
help@w3schools.com

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookies and privacy policy.

Copyright 1999-2025 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.