Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / CSS

scale(): resize the rendering, not the layout

Scale one or both axes, reflect with a negative factor, and keep the distinction from normal-flow sizing.

Version: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, per-example verification still required

Syntax

transform: scale(2, 0.5);

The function scale() applies a two-dimensional scale around transform-origin. Its first factor affects X and its optional second factor affects Y; when the second is omitted, it equals the first. A factor of 1 leaves that axis unchanged, 2 doubles it, and a fraction shrinks it. Percentages are equivalent ratios, so 200% means 2 rather than a percentage of the parent width. This function belongs inside transform; the separate scale property has its own syntax.

A negative factor reflects the axis. A zero factor makes the transform non-invertible, so the transformed box and its content are not displayed, although the original layout space remains. Scaling affects painting and visual bounds rather than reflowing neighbours; it can therefore cause overlap. Different X and Y factors distort proportions, including text. Order also matters when scaling is combined with translations or rotations.

The example scales an 80px by 30px box with scale(2,0.5): its visible bounds become 160x15, but layout stays 80x30 and the next block still begins at 30. The single value scale(200%) makes the bounds 160x60. With scale(-1,1), local point 10,0 becomes -10,0. Finally scale(0) collapses the bounds to 0x0 while the layout dimensions remain 80x30.

Examples

document.body.style.margin='0';
const box=document.createElement('div'),next=document.createElement('div');
box.style.cssText='width:80px;height:30px;transform-origin:0 0;transform:scale(2,0.5)';
next.style.cssText='width:10px;height:10px';document.body.append(box,next);
const size=()=>{const r=box.getBoundingClientRect();return [r.width,r.height].map(v=>Math.round(v)).join('x')};
console.log('visual='+size()+'; layout='+box.offsetWidth+'x'+box.offsetHeight+'; next-top='+next.getBoundingClientRect().top);
box.style.transform='scale(200%)';console.log('uniform='+size());
box.style.transform='scale(-1,1)';const p=new DOMMatrix(getComputedStyle(box).transform).transformPoint(new DOMPoint(10,0));console.log('mirrored-point='+p.x+','+p.y);
box.style.transform='scale(0)';console.log('collapsed='+size()+'; retained-layout='+box.offsetWidth+'x'+box.offsetHeight);

Result

visual=160x15; layout=80x30; next-top=30
uniform=160x60
mirrored-point=-10,0
collapsed=0x0; retained-layout=80x30

The example measures visual bounds, layout dimensions and the next block separately. Enlarging with transform does not reserve additional normal-flow space.

Sources