The transform property lets you change how an element looks by moving, rotating, scaling, or skewing it. It helps make web pages more lively and interactive.
Transform property in CSS
Start learning this pattern below
Jump into concepts and practice - no test required
transform: none | transform-function(s);You can use one or more transform functions separated by spaces.
Common functions include translate(), rotate(), scale(), and skew().
transform: translateX(50px);
transform: rotate(45deg);transform: scale(1.5);
transform: translate(20px, 10px) rotate(30deg);
This example shows a green box that moves up, rotates slightly, and grows bigger when you hover or focus on it. The transition makes the change smooth. The box is keyboard accessible with tabindex="0" and has an ARIA label for screen readers.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Transform Property Example</title> <style> .box { width: 100px; height: 100px; background-color: #4CAF50; margin: 2rem auto; transition: transform 0.5s ease; display: flex; align-items: center; justify-content: center; color: white; font-weight: bold; border-radius: 0.5rem; user-select: none; } .box:hover, .box:focus { transform: translateY(-20px) rotate(15deg) scale(1.2); cursor: pointer; outline: none; } </style> </head> <body> <main> <section> <div class="box" tabindex="0" aria-label="Interactive green box">Hover or focus me!</div> </section> </main> </body> </html>
Use transition to make transform changes smooth and nice to watch.
Transforms do not affect the space the element takes on the page, so other elements do not move when you transform.
Remember to add tabindex="0" and ARIA labels for better accessibility when using interactive transforms.
The transform property changes how an element looks by moving, rotating, scaling, or skewing it.
You can combine multiple transform functions for creative effects.
Use transitions and accessibility features to make transforms smooth and user-friendly.
Practice
transform property do?Solution
Step 1: Understand the purpose of
Thetransformtransformproperty visually changes elements by moving, rotating, scaling, or skewing them.Step 2: Compare with other CSS properties
Changing background color, borders, or visibility are done by other CSS properties, nottransform.Final Answer:
It changes the position, size, or shape of an element visually. -> Option AQuick Check:
Transform = Visual change in shape/position [OK]
- Confusing transform with color or visibility properties
- Thinking transform changes content instead of appearance
- Mixing transform with layout properties like margin or padding
transform?Solution
Step 1: Recall correct function syntax for rotate
Therotatefunction requires parentheses and a unit, likerotate(45deg).Step 2: Check each option's syntax
transform: rotate(45deg); uses correct syntax with parentheses and unit. Options A, B, and D miss parentheses, equal sign, or units.Final Answer:
transform: rotate(45deg); -> Option CQuick Check:
Rotate needs parentheses and units [OK]
- Omitting parentheses around the angle
- Forgetting the unit 'deg' for degrees
- Using equal sign instead of colon or parentheses
div {
transform: translateX(50px) scale(2);
width: 100px;
height: 100px;
background-color: blue;
}Solution
Step 1: Understand translateX and scale
translateX(50px)moves the element 50 pixels to the right.scale(2)doubles the element's size.Step 2: Combine effects on the blue square
The square moves right by 50px and becomes twice as wide and tall, so it appears bigger and shifted right.Final Answer:
A blue square moved 50px right and doubled in size. -> Option DQuick Check:
translateX = right move, scale = size change [OK]
- Confusing translateX with translateY (vertical move)
- Thinking scale only changes width or height, not both
- Ignoring the order of transform functions
p {
transform: rotate 30deg;
}Solution
Step 1: Check syntax for rotate function
Therotatefunction requires parentheses around the angle, likerotate(30deg).Step 2: Review other options for correctness
Units like 'deg' are required. The property is correctly namedtransform. Rotate works on any element.Final Answer:
Missing parentheses around the angle value. -> Option AQuick Check:
Rotate needs parentheses around angle [OK]
- Omitting parentheses in transform functions
- Thinking 'deg' is invalid unit for rotate
- Confusing property names like transform-rotate
transform property correctly combines these effects?Solution
Step 1: Understand order of transform functions
Transforms are applied left to right. To scale first, then rotate, writescale(1.5) rotate(90deg).Step 2: Check syntax for combining transforms
Transforms are combined by space-separated functions without operators or missing parentheses. transform: scale(1.5) rotate(90deg); is correct syntax.Final Answer:
transform: scale(1.5) rotate(90deg); -> Option BQuick Check:
Combine transforms with space, order matters [OK]
- Using '+' operator between transform functions
- Omitting parentheses or units
- Reversing order and changing visual effect
