scale()
Example
.thumb:hover img {
width: 110%;
height: 110%;
}.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 animatingwidthandheight. transform-originis set when scaling must grow from a corner or edge instead of the center.- Images zoomed inside a card are clipped with
overflow: hiddenon 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.