CHAPTER 53

CSS 2D Transforms

Learn how translate, rotate, scale and skew transform elements in two dimensions.

01. What is CSS 2D Transforms?

CSS transforms can move, rotate, resize and skew elements.
2D transforms work on the horizontal and vertical plane.
Transforms can be combined to create interactive effects.

02. Syntax

transform: translate(x, y); transform: rotate(angle); transform: scale(value); transform: skew(x, y);

03. Example

CSS / HTML Example AIFA Coding Lab
<!DOCTYPE html>
<html>
<head>
<style>
.box {
    width: 150px;
    height: 150px;
    background: #2563eb;
    transition: .3s;
}

.box:hover {
    transform:
        rotate(8deg)
        scale(1.08)
        translateX(10px);
}
</style>
</head>
<body>
<div class="box"></div>
</body>
</html>

04. Important Points

✓ translate moves an element.
✓ rotate rotates an element.
✓ scale changes its size.
✓ skew slants an element.
✓ Transforms can be combined.

05. Common Mistakes

⚠ Using extreme transformations.
⚠ Forgetting transition when a smooth effect is required.
⚠ Transforming important content in a distracting way.

06. Real World Use

2D transforms are used for hover cards, buttons, menus, image effects and interactive UI components.

Ready to Practice? 🚀

Open the AIFA CSS Editor and practice this chapter live.

Try It Yourself →
Practice Exercise

Create a Hover Transform

Create a box that rotates and scales slightly when the mouse moves over it.