Course contentsShow
← Web Development
Lesson 530 of 2,9829. CSS Transitions and AnimationsFree lesson

Scaling Elements with scale()

Resizing elements proportionally or independently on each axis using scale(), scaleX(), and scaleY().

Scaling Elements with scale()

You'll learn how to resize elements proportionally or independently using CSS transform scale functions.

What Is scale()?

The scale() transform function lets you shrink or enlarge an element from its center point without affecting the document layout around it. Think of it like zooming a photo in or out—the photo gets bigger or smaller, but it doesn't push other photos on your desk around.

The Core Syntax

You can scale elements in three ways:

scale(value) — Scales both width and height equally:

.box {
  transform: scale(1.5); /* 150% of original size */
}

scaleX(value) — Scales only the width:

.box {
  transform: scaleX(0.5); /* Half the width */
}

scaleY(value) — Scales only the height:

.box {
  transform: scaleY(2); /* Double the height */
}

How Values Work

  • scale(1) = original size (no change)
  • scale(2) = 200% size (doubled)
  • scale(0.5) = 50% size (halved)
  • scale(0) = invisible (collapsed to nothing)

You can also provide two values to scale() for different horizontal and vertical scaling:

.box {
  transform: scale(1.5, 0.75); /* 150% wide, 75% tall */
}

Practical Example

.card:hover {
  transform: scale(1.1); /* Subtle zoom on hover */
}

.squish {
  transform: scaleY(0.5); /* Flatten vertically */
}

Key Takeaway: Use scale() to resize elements proportionally, or scaleX() and scaleY() to control width and height independently—all without disrupting surrounding layout.