Course contentsShow
← Web Development
Lesson 2552 of 2,98246. Animation LibrariesFree lesson

Animating CSS Properties

Learn which CSS properties GSAP can animate and how to specify transforms, opacity, and colors.

Animating CSS Properties

You'll learn which CSS properties GSAP can animate and how to target transforms, opacity, and colors.

Now that you understand GSAP's core animation methods and easing, it's time to explore what you can actually animate. GSAP shines because it can animate virtually any numeric CSS property—and it handles the syntax beautifully.

Which Properties Can You Animate?

GSAP can animate any property with numeric values: width, height, padding, margin, fontSize, borderRadius, and more. Simply pass them as camelCase properties in your animation object.

The real power comes with transforms, opacity, and colors—the properties that create smooth, performant animations.

Transforms: The Performance Champions

Instead of animating left and top (which trigger layout), use transform properties:

gsap.to(".box", {
  x: 100,           // translateX
  y: 50,            // translateY
  rotation: 45,     // rotate in degrees
  scale: 1.5,       // uniform scale
  duration: 1
});

Notice GSAP's shorthand: x instead of translateX, rotation instead of rotate. These are easier to write and GPU-accelerated for buttery-smooth motion.

Opacity: Simple Yet Essential

gsap.to(".fade", { opacity: 0, duration: 0.5 });

Perfect for fade effects—no special syntax needed.

Colors: Automatic Conversion

GSAP understands hex, RGB, RGBA, and named colors:

gsap.to(".button", {
  backgroundColor: "#ff6b6b",  // from any starting color
  color: "rgb(255, 255, 255)",
  borderColor: "blue",
  duration: 0.3
});

GSAP automatically interpolates between color formats—you don't need to convert them yourself.

Combining Properties

Mix and match freely:

gsap.to(".hero", {
  x: 200,
  opacity: 0.5,
  backgroundColor: "#333",
  scale: 0.8,
  duration: 2
});

Key Takeaway: GSAP animates any numeric CSS property with camelCase syntax; use transform shortcuts (x, y, rotation, scale) for performant animations, and let GSAP handle color conversions automatically.