scale()

Term side of the Card.
Topic: Transformations
Unit title: scale()
Categories: Function
Explanation side of the Card

Explanation: The function that scales an element by a specified factor along both the X and Y axes. It increases or decreases the size of an element proportionally, enabling to zoom in or out on an element while maintaining its original aspect ratio.

Browser compatibility:
  • The chrome browser supports this feature starting from version 1.
  • The edge browser supports this feature starting from version 12.
  • The firefox browser supports this feature starting from version 3.5.
  • The safari browser supports this feature starting from version 3.1.
Availability: 

Example

Wrongcss
.thumb:hover img {
  width: 110%;
  height: 110%;
}
Rightcss
.thumb {
  overflow: hidden;
}
.thumb img {
  transition: transform 0.3s;
}
.thumb:hover img {
  transform: scale(1.1);
}

scale() zooms without changing layout, and overflow: hidden keeps the image inside its frame.

Common mistakes

  • Text inside a scaled element looks blurry during the animation.
  • A zoomed image spills out of its rounded card.

Key points

  • Hover zoom uses transform: scale() instead of animating width and height.
  • transform-origin is set when scaling must grow from a corner or edge instead of the center.
  • Images zoomed inside a card are clipped with overflow: hidden on the wrapper.

Interview questions

Does scale() change the element's size in the layout?

No. The element keeps its layout box; only its painted size changes, so neighbors do not move.

How do I flip an element with scale()?

Use a negative value: scale(-1, 1) mirrors it horizontally, and scale(1, -1) flips it vertically.

Analytics cookiesWe'd like to use analytics cookies to see which pages are useful. They're set only if you accept. Privacy Policy