Skip to main content

The CSS scale() Function

Give scale() two values, the first for width and the second for height, and the element grows or shrinks accordingly.

Scale up

Here a <div> element ends up twice as wide and three times as tall as it started.

Prompt
Create an HTML page with a div element that uses CSS transform: scale(2, 3) to increase its size to two times the original width and three times the original height. Show the div with some text inside and a background color so the scaling effect is visible.
Output: complete HTML page

Scale down

Here both dimensions of a <div> element are cut to half their starting size.

Prompt
Create an HTML page with a div element that uses CSS transform: scale(0.5, 0.5) to decrease its size to half of its original width and height. Show the div with some text inside and a background color so the scaling effect is visible.
Output: complete HTML page

The CSS scaleX() Function

Only the width of an element changes with scaleX(), which can grow or shrink it.

Increase width

A factor of 2 doubles the starting width of this <div> element.

Prompt
Create an HTML page with a div element that uses CSS transform: scaleX(2) to increase its width to two times the original width. Show the div with some text inside and a background color so the effect is visible.
Output: complete HTML page

Decrease width

A factor of 0.5 narrows this <div> element to half the width it started with.

Prompt
Create an HTML page with a div element that uses CSS transform: scaleX(0.5) to decrease its width to half of its original width. Show the div with some text inside and a background color so the effect is visible.
Output: complete HTML page

The CSS scaleY() Function

With scaleY(), the height is the only dimension that changes, either upward or downward.

Increase height

A factor of 3 makes this <div> element three times as tall as it started.

Prompt
Create an HTML page with a div element that uses CSS transform: scaleY(3) to increase its height to three times its original height. Show the div with some text inside and a background color so the effect is visible.
Output: complete HTML page

Decrease height

A factor of 0.5 shortens this <div> element to half the height it started with.

Prompt
Create an HTML page with a div element that uses CSS transform: scaleY(0.5) to decrease its height to half of its original height. Show the div with some text inside and a background color so the effect is visible.
Output: complete HTML page