The transform property allows developers to visually manipulate an element's geometric coordinate space without disrupting the normal document flow. You can translate (move), rotate, scale (resize), and skew elements in both 2D and 3D planes.
| Transform Function | Visual Manipulation | Example Snippet |
|---|---|---|
translate(x, y) |
Moves the element along horizontal X and vertical Y axes. | transform: translate(20px, -10px); |
rotate(angle) |
Rotates the element clockwise or counter-clockwise around its origin. | transform: rotate(45deg); |
scale(x, y) |
Enlarges or shrinks the element. 1 is 100%, 1.1 is 110%. |
transform: scale(1.05); (Zoom hover) |
skew(x-angle, y-angle) |
Shears the element along an angle, turning rectangles into parallelograms. | transform: skewX(-15deg); (Italic banner) |
To create realistic 3D depth, you must first define a perspective viewing distance on the parent container (typically between 500px and 1000px):
/* 1. Parent creates 3D depth canvas */
.scene {
perspective: 800px;
}
/* 2. Child Card rotates in 3D space */
.card-3d {
transform: rotateY(25deg) rotateX(10deg);
transform-style: preserve-3d;
transition: transform 0.5s ease;
}
Hover over a product card to reveal its backside in true 3D:
.card-inner {
position: relative;
width: 300px;
height: 200px;
transform-style: preserve-3d;
transition: transform 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}
.card:hover .card-inner {
transform: rotateY(180deg);
}
.card-front, .card-back {
position: absolute;
inset: 0;
backface-visibility: hidden; /* Hides reverse side when flipped */
border-radius: 8px;
}
.card-back {
transform: rotateY(180deg);
background-color: #d22b2b;
color: #ffffff;
}
Boost your CSS and front-end development proficiency by exploring these closely connected topics:
Understand margins, borders, padding, content and the universal box-sizing fix.
Master 1D alignment, justify-content, align-items, flex-wrap and responsive flow.
Build powerful two-dimensional grid layouts with template areas and fr units.
Eliminate styling conflicts and master selector weights from 0,0,0,1 to !important.