CSS propertyTransforms
scale
Enlarges or shrinks an element, independently of the transform property.
- Initial value
none- Inherited
- No
- Animatable
- yes, as a number
- Applies to
- transformable elements
- JavaScript
element.style.scale = "1.1"
Example
#CSS
.button {
transition: scale 0.15s;
}
.button:active {
scale: 0.95;
}Example HTML
<style>.press { transition: scale .15s; } .press:active { scale: 0.95; }</style>
<button class="press" type="button" style="padding: 10px 18px; border-radius: 10px;">Press and hold me</button>Preview
Definition and usage
#The scale property changes the visual size of an element. A value of 1 is the natural size, 2 doubles it, and 0.5 halves it. Two values scale horizontally and vertically separately.
Scaling does not change the page layout, so an enlarged element overlaps its neighbours instead of pushing them away. That is exactly what you usually want for hover effects.
A negative value creates a mirror image: scale: -1 1 flips the element horizontally.
Syntax
#Syntax
scale: none | <number> <number>? <number>?;Values
#Values in practice
#none
Natural size.
.demo { scale: none; }1.4
Enlarges by 40% on both axes.
.demo { scale: 1.4; }0.6
Shrinks to 60%.
.demo { scale: 0.6; }1.6 0.8
Stretched horizontally, squeezed vertically.
.demo { scale: 1.6 0.8; }-1 1
Mirror image horizontally.
.demo { scale: -1 1; }Browser support
#Widely available
Works in all modern browsers, phones included. You can use it without worry.
- Chrome
- Edge
- Firefox
- Safari
Good practices
#- Slightly shrinking a button in the
:activestate (0.95-0.98) gives a pleasant pressed feeling. - Text in an enlarged element can look blurry. For large size changes, it is better to change the real dimensions.
Related entries
#- transformMoves, rotates, scales, or skews an element without affecting the page layout.
- transform-originSets the point an element rotates around and scales from.
- rotateRotates an element by a given angle, independently of the transform property.
- translateMoves an element horizontally, vertically, or in depth, independently of the transform property.
Spotted a mistake or missing an example? Write to us.