Scale - Property CSS
Summary of characteristics of the scale property
nonenoneComputed value: during an animation, the scale property gradually changes from one value to another.Syntactic schema of scale.
The terms in the diagram are described below:
numberis the coefficient of magnification or reduction (positive or negative number, without units).§is a percentage.- The syntax can be repeated from one to 3 times.
Description of the scale property.
The scale property defines a transformation of the element (in the CSS sense), i.e. its scaling,
that is to say, its enlargement or reduction.
The resizing is applied equally to all children of the element.
Like all transformations, the scale effect does not interact with the layout: even if the element gets bigger or smaller,
everything that is located after it will not be moved. We can therefore find ourselves in the situation where several elements overlap.
scale expects three values, which correspond to the magnification or reduction coefficients along the axes
X, Y and Z. These are defined as follows:
- The X-axis is the horizontal axis.
- The Y-axis is the vertical axis. These two axes are in the plane of the screen.
- The Z axis is perpendicular to the plane of the screen, directed from the screen towards the reader's eye.
In accordance with the usual rules of CSS, the effects of several successive scale properties applied to the same selector, do not accumulate.
Thus the code below leaves the element with dimensions reduced by half: the first ruler is replaced by the second, and is ignored.
scale: 2;
scale: 0.5;
Values for scale.
- scale: none;
No scaling is applied to the element.
Échantillon - scale: 2;
If only one unique value is specified, the width and height of the element are multiplied by this coefficient.
This is a number without units. Percentages can be used, and are calculated in relation to Initial dimensions of the element:
200%corresponds to a doubling of the size of the element.Échantillon - scale: 3 1.5;
When two numbers are specified, they correspond respectively to the coefficients to be applied the width of the element (x-axis) and the height of the element (y-axis). The dimension along the z-axis is not changed.
Échantillon - scale: 2 0.75 2;
When a third value is specified, it applies to the thickness of the element (
Zaxis).
Percentages are forbidden for the Z axis.Dimension changes along the
Z-axisare invisible because the thickness of the element is initially zero. However, applying a value of0to the third value makes the element disappear, as does a0on the first or second value.On the other hand, if the element has been rotated with
transform:rotateX(...)ortransform:rotateY(...),the dimension change along the axisZwill have a visible effect. This will not be the case if the element has been rotated with therotateproperty.Échantillon - scale: initial; (
none) scale: inherit; scale: revert; scale: revertLayer; scale: unset;These values are described in more detail on their respective page:
initial,inherit,revert,revert-layer,unset.
el parameter represents the element on the page that you want to scale.
Animation of the scale property.
As you might expect, the animation of scale can very easily give interesting visual effects.
Manipulating the scale property programmatically.
In the code examples below, the el parameter represents the element on the page that you want to scale.
In Javascript, here's how to change the value of scale.
Javascript offers a syntax with an array-type notation, with square brackets, and another syntax closer to the usual object notation.
function setScale(el) {
el.style['scale']='1 2 1';
}
function setScale(el) {
el.style.scale='1 2 1';
}
To read the CSS value of scale Javascript also supports two syntaxes.
These codes return the value of the property assigned directly to the element, not through a class or other selector.
The value returned can be either the word none or the numbers assigned to the property (from 1 to 3), with percentages replaced by
the corresponding numerical value.
function getScale(el) {
return el.style['scale'];
}
function getScale(el) {
return el.style.scale;
}
To read the computed value of scale in Javascript, use the code below.
function getScale(el) {
return window.getComputedStyle(el).getPropertyValue('scale');
}
With JQuery, here are code examples to change the value or reread the calculated value of the scale property.
function setScale(el) {
$(el).css('scale','1 2 1');
}
function getScale(el) {
return $(el).css('scale');
}
Test it yourself.
The buttons below apply the value to the scale property and then display either the value as applied,
or the calculated value. This second option allows you to see how the value of scale is stored (serialized). In particular, we note
that the percentages are reduced to coefficients and that the value of Z, if it is equal to 1, is not memorized.
Simulator.
Browser compatibility.
Browsers now recognize the scale property.
The transform property with the scale() function is another well-recognized solution.
the backface-visibility property.scale which defines scaling coefficients for enlarging or reducing the element.Notes:
(1) Does not support 2D transformations on SVG elements. Use the transform attribute instead.
(2) Internet Explorer does not support transform-style:preserve-3d, thus limiting the nesting of animations.
transformations
transformations
scaleproperty
Browsers on computers :
Mobile browsers :
Outdated or marginal browsers :

Internet Explorer

KaiOS Browser

Opéra Mobile

Opéra

Firefox pour Androïd

Samsung Internet

Chrome

Edge

Firefox

Androïd Brower

Chrome pour Androïd

Baidu Browser

QQ Browser

Safari

Safari sur IOS

UC Browser pour Androïd

Opéra mini
Property scale history.
-
CSS Transforms Module Level 2
Adding thescaleproperty in addition to thetransformproperty and thescale()function.March 03, 2020Working Draft.
See also, concerning transformations.
The CSS Transforms Module contains all the definitions of CSS transformations:
Properties:





Functions:





