CSS - scale Property



The CSS property scale is useful in specifying the scale transformation of elements, independent of transform property.

This property is convenient for interface use, as you need not remember the order transform functions to be specific in the property transform.

Possible values

The CSS property scale can have one of the following values:

  • Single value: Specifies a <number> or <percentage> value to scale an element by the same value along X and Y axis. Equivalent to scale() 2D function, with a single value.

  • Two values: Specifies two <number> or <percentage> values to scale an element by the given values along X and Y axis. Equivalent to scale() 2D function, with two values.

  • Three values: Specifies three <number> or <percentage> values to scale an element by the given values along X, Y, and Z axis, respectively in a 3D scale. Equivalent to scale3d() function.

  • none: Specifies no scaling to be applied.

Applies to

All the transformable elements.

Syntax

scale = none | <number> | <percentage> ] {1,3}

CSS scale - Element Scaling

Following example demonstrates the use of scale CSS property, with various ways of passing values. The element gets scaled on hover:

<html>
<head>
<style>
   .box {
      display: inline-block;
      margin: 0.7em;
      min-width: 5.5em;
      line-height: 6.5em;
      text-align: center;
      transition: 2s ease-in-out;
      border: 2px solid black;
      background-color: lightgreen;
   }

   #scale-one-box:hover {
      scale: 2;
   }

   #scale-two-box:hover {
      scale: 1.5 65%;
   }

   #scale-three-box:hover {
      scale: 20% 40% 60%;
   }
</style>
</head>
<body>
   <h1>CSS Scale property</h1>
   <div class="box" id="scale-one-box">scale (x)</div>
   <div class="box" id="scale-two-box">scale (x,y)</div>
   <div class="box" id="scale-three-box">scale (x,y,z)</div>
</body>
</html>
Advertisements