Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / CSS

scaleX(): horizontal scaling and reflection

Resize the rendered X axis, mirror content with a negative factor and control the origin.

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

Syntax

transform: scaleX(-1);

scaleX(s) changes the horizontal coordinate while leaving the Y factor at 1. A factor above 1 stretches the rendered width; a positive fraction compresses it. A negative factor also mirrors the content horizontally. The percentage form uses 100%=1, not a percentage of a containing block; 2px is invalid.

Scaling takes place around transform-origin, which is normally the center of the reference box for an ordinary CSS box. Changing it to 0 0 makes the left edge the reference. This affects where mirrored content appears. A zero factor creates a non-invertible transform and the element is not displayed; it is not a replacement for removing the element from layout.

With a 40×30px box starting at x=60 and origin 0 0, scaleX(2) gives edges 60 and 140, while scaleX(-1) gives 20 and 60. Moving the origin to the center keeps the mirrored rectangle at 60–100. scaleX(0) collapses its measured width to zero at x=80, but its layout size remains 40×30 throughout.

Examples

const box=document.createElement('div');
box.style.cssText='position:fixed;left:60px;top:60px;width:40px;height:30px;transform-origin:0 0';
document.body.append(box);
const measure=value=>{box.style.transform=value;const r=box.getBoundingClientRect();return [r.left,r.right,r.width,r.height].join(',')};
const doubled=measure('scaleX(2)');
const reflected=measure('scaleX(-1)');
box.style.transformOrigin='50% 50%';
const centered=measure('scaleX(-1)');
const zero=measure('scaleX(0)');
console.log('double='+doubled+'; mirror='+reflected+'; center-mirror='+centered+'; zero='+zero+'; layout='+box.offsetWidth+'x'+box.offsetHeight+'; percent='+CSS.supports('transform','scaleX(50%)')+'; length='+CSS.supports('transform','scaleX(2px)'));

Result

double=60,140,80,30; mirror=20,60,40,30; center-mirror=60,100,40,30; zero=80,80,0,30; layout=40x30; percent=true; length=false

The rectangle cannot show that text is mirrored; the negative factor supplies that reflection. getBoundingClientRect measures transformed geometry, whereas offsetWidth still reports the layout width.

Sources