Skip to main content
Brave Programmer Logo

BraveProgrammer

BraveProgrammer

HomeProjectsBlogsCoursesLessonsAbout

Site footer

BraveProgrammer

Free coding courses, practical tutorials, and real projects from BraveProgrammer. Learn web development with React, Next.js, and TypeScript.

Navigation

  • Home
  • Projects
  • Blogs
  • Courses

Resources

  • About
  • Lessons
  • Teach on BraveProgrammer

© 2026 BraveProgrammer. All rights reserved.

Transforms | CSS Basics to Advanced lesson | BraveProgrammer
  1. Courses
  2. /
  3. CSS Basics to Advanced

Lesson 21 of 50

·css

Transforms

10 mins

Course progress42%

What you'll learn

Keep these ideas in mind as you work through the lesson.

4 points
  • `transform` creates a new **stacking context**.
  • `translate` moves an element without affecting the document flow.
  • `rotate`, `scale`, `skew` are common for UI motion.
  • Use `transform-origin` to control the pivot point.

Transforms modify an element's visual rendering without changing its layout footprint. They are extremely cheap for the GPU and form the backbone of most UI motion.

2‑D Transform Functions

FunctionDescription
translate(x, y)Moves the element along the X/Y axis.
rotate(angle)Rotates around the element’s origin.
scale(x, y)Scales width/height proportionally (scale(1.2) equals scale(1.2, 1.2)).
skew(x-angle, y-angle)Tilts the element along each axis.

3‑D Transforms (experimental but widely supported)

  • perspective(<length>) – defines the distance between the viewer and the z‑plane.
  • rotateX(), rotateY(), rotateZ() – rotate around a single axis.
  • translateZ() – move on the z‑axis (creates depth).

Example – 3‑D Card Flip

.card {
  perspective:1000px;               /* create 3‑D space */
}
.inner {
  transition:transform .6s;
  transform-style:preserve-3d;      /* keep children in 3‑D */
}
.card:hover .inner {                 /* flip on hover */
  transform:rotateY(180deg);
}
.front, .back {
  position:absolute; inset:0; backface-visibility:hidden; /* hide backside */
}
.back { transform:rotateY(180deg); }

The card appears to rotate in 3‑D space, revealing its back face.


Stacking Context

Any element with transform (even transform:none) creates a new stacking context. This means its children will be stacked inside it, unaffected by siblings’ z-index.

Practical Tip – Use transform-origin

Changing the pivot point can make a subtle difference:

button { transform-origin: left center; }

The button now rotates around its left edge instead of the centre.

Make it stickPractice what you've learned1 quiz · 6 practical tests · Optional activities from CSS Basics to AdvancedBrowse activities
Previous lessonTransitionsContinue to lesson 22Keyframe AnimationsBack to CSS Basics to Advanced curriculum