What is CSS scale() Function?

Learn via video course
FREE
View all courses
JavaScript Course With Certification: Unlocking the Power of JavaScript
JavaScript Course With Certification: Unlocking the Power of JavaScript
by Mrinal Bhattacharya
1000
4.8
Start Learning
JavaScript Course With Certification: Unlocking the Power of JavaScript
JavaScript Course With Certification: Unlocking the Power of JavaScript
by Mrinal Bhattacharya
1000
4.8
Start Learning
Topics Covered

Introduction

The CSS scale() function scales an element in two-dimensional space. The CSS scale property proportionally changes the width and height of an element. Therefore, scaling up by a value of 2 increases the dimensions of a 10-pixel element to a 20-pixel element. Similarly, a CSS scale value of 0.5 halves the dimension of the element to 5 pixels.

Transform Your Career

Choose from our industry-leading programs designed for career success

NSDC Certified

Modern Software and AI Engineering Program

Master full-stack development with AI integration

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Modern Data Science and ML with specialisation in AI

Advanced data science techniques with AI specialization

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Advanced AIML with Specialisation in Agentic AI

Deep dive into AIML with focus on Agentic systems

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

DevOps, Cloud & AI Platform Engineering

Build and manage AI-powered cloud infrastructure

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

AI Engineering Advanced Certification by IIT-Roorkee

Premier AI engineering certification from IIT-Roorkee

3 MonthsDuration
AI-LedCurriculum
Career SupportSupport
Program highlights
Go to Program

Syntax

Scale() accepts either one or two values representing the amount of scaling in each direction.

The general Syntax is expressed as:

The single parameter assigns the value evenly to both the X and Y axis.

Other syntax with two arguments

sx resizes the elements horizontally, and sy resizes the elements in the vertical plane.

Values of CSS scale() Function

ValueDescription
noneIt represents no scaling and is the same as scale: 1
sxIt is a number of a percentage that represents the abscissa of the scaling vector.
byIt is a number of a percentage that represents the ordinate of the scaling vector.
{1,3}A number is either an integer or zero or more decimal digits. <number>{1,3} states that the property accepts up to three values used to multiply the element’s dimensions.

Examples

Free Courses by top Scaler instructors
Python Course for Beginners With Certification: Mastering the Essentials
Java Course - Mastering the Fundamentals
DBMS Course - Master the Fundamentals and Advanced Concepts
JavaScript Course With Certification: Unlocking the Power of JavaScript
C++ Course: Learn the Essentials
Python and SQL for Data Science
Python Course for Beginners With Certification: Mastering the Essentials
Java Course - Mastering the Fundamentals
DBMS Course - Master the Fundamentals and Advanced Concepts
JavaScript Course With Certification: Unlocking the Power of JavaScript
C++ Course: Learn the Essentials
Python and SQL for Data Science

Example 1: Scaling the X and Y Dimensions Together

HTML

CSS

Output Scaling the X and Y Dimensions Together

Scaler Placement Report and Statistics

₹23L
AVG CTC
SCALER PLACEMENT PROOF

Scaler learners achieved 2.5x salary growth with average post-Scaler CTC reaching ₹23L.

11,000+placements
650+companies
Verified data
Hiring Partners:
GoogleGoogleAmazonAmazonMicrosoftMicrosoftFlipkartFlipkartAdobeAdobe1200+ more

Example 2: Scaling X and Y Dimensions Separately, and Translating the Origin

HTML

CSS

Output Scaling the X and Y dimensions together

Scaling Does not Distort the Natural Layout Flow

The scale property does not make other adjacent elements flow around it like the scale() transform function does. It does not cause the components surrounding it to reflow to create the extra (or less) space needed based on the scale of that element.

In the below example, we will scale the box in the center without affecting the layout of the adjacent elements.

HTML

  • Here, we have a container with a class scale-box surrounded by two other boxes.
  • A range slider to scale the middle box dynamically.

CSS

Javascript

  • To scale the container using multiple values, we will use javascript.
  • We will set the scale value to scale(1,1) as a default value.
  • We will add an event listener and scale the box according to the range value.

Output

Scaling does not distort the natural layout flow

Turn Learning into Career Growth

1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary
1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary

Scaling Affects the Child and Descendent Elements

The scale property scales all of an element’s descendants. For example, let’s say we have text inside the element. If we change the elements scale, the scale property scales both the element and the text.

HTML

CSS

Javascript

Output

The text is a child element of the div scales with the container. Scaling affects the child and descendent elements

Fallbacks

Although almost all modern web browsers support the CSS scale and other independent transform properties, we can always check for fallbacks and support.

Example

Browser compatibility

The following browsers support the scale() in CSS:

BrowserVersion
Google Chrome1.0
Safari3.1
Mozilla Firefox1.0
Microsoft Edge12.0
Chrome Android18
Firefox for Android4
Opera Android11
Safari on iOS3.2
Samsung Internet1.0
WebView Android2

Conclusion

  • The CSS scale() function scales an element in two-dimensional space.
  • Scale() accepts either one or two values representing the amount of scaling in each direction as scale(six) or scale(sx,sy),respectively.
  • sx resizes the elements horizontally, and sy resizes the elements in the vertical plane.
  • Scaling does not distort the natural layout flow
  • The scale property scales all of an element’s descendants.