Skip to main content
SVG Logo Animation with GreenSock (GSAP) - A Step-by-Step Guide

SVG Logo Animation with GreenSock (GSAP) - A Step-by-Step Guide

SVG Logo Animation

In this tutorial we show you how to animate an SVG logo elegantly with the JavaScript animation library GreenSock (GSAP). Step by step we animate our own logo and explain how to use the timeline and tween functions effectively.

What Are We Trying to Achieve?

The animation below shows our pixelparker brand logo – and this is exactly the motion we want to reproduce in our own project.

With a few lines of code we create a fluid SVG animation in which the letters, the head and the glasses fade in one after another.

Step 1 – Install the Framework

We use GreenSock (GSAP) as the framework for animating the SVG elements. Installing it via npm is straightforward:

npm i gsap

Then include the files you need in your project. As a rule, Timeline and Tween are enough. You only need the max version if you use additional components.

Detailed documentation on using it through npm is available on the official GreenSock website.

Step 2 – Add the SVG to Your HTML

Copy the SVG code straight into your HTML file. That way you can give individual elements their own CSS classes and target them from GSAP. For example:

<svg viewBox="0 0 500 200">
  <g>
    <path class="head" d="..." />
    <path class="glasses" d="..." />
    <rect class="letter" x="..." y="..." />
    <rect class="letter" x="..." y="..." />
  </g>
</svg>

Important: use unambiguous class names (head, glasses, letter) so you can target them precisely later.

Step 3 – Prepare the JavaScript

Next we grab the SVG elements with JavaScript and store them in variables:

let head = document.getElementsByClassName("head");
let glasses = document.getElementsByClassName("glasses");
let letters = document.getElementsByClassName("letter");

Now we create a new timeline so we can run several animations in sequence:

let tlLetters = new TimelineMax();

First we set the starting values of the elements – the opacity, for instance:

tlLetters.set(letters, { opacity: 0 });

Step 4 – Animation with a Stagger Effect

Now we define the animation for the letters. The staggerFromTo() function lets us animate every element of the NodeList (here letters) one after another with a slight offset:

tlLetters.staggerFromTo(
  letters,
  0.15,               // duration of the animation
  {
    transformOrigin: "50% 50%",
    scale: 1.25,
    opacity: 0
  },
  {
    scale: 1,
    opacity: 1
  },
  0.2                 // offset between the animations
);

With transformOrigin we make sure the scaling happens from the center – keeping the animation visually balanced.

Step 5 – Animate the Head and Glasses

For the head and the glasses we define a separate timeline and add a delay:

let tlHead = new TimelineMax();

tlHead.set(head, { opacity: 0, scale: 1.3 });
tlHead.set(glasses, { opacity: 0, scale: 1.3 });

tlHead.delay(1.5);

tlHead.to(head, 0.5, { opacity: 1, scale: 1 });
tlHead.to(glasses, 0.5, { opacity: 1, scale: 1 });

The delay() method makes sure the head and glasses only start once the letter animation has finished. The result is a harmonious, professional effect.

Step 6 – Compatibility and ES5

To make sure your animation runs in every browser, it is worth transpiling the code to ES5 (with Babel, for example). That improves compatibility, especially with older browsers.

The Complete Code at a Glance

// Get the elements
let head = document.getElementsByClassName("head");
let glasses = document.getElementsByClassName("glasses");
let letters = document.getElementsByClassName("letter");

// Timeline for the letters
let tlLetters = new TimelineMax();
tlLetters.set(letters, { opacity: 0 });
tlLetters.staggerFromTo(
  letters, 0.15,
  { transformOrigin: "50% 50%", scale: 1.25, opacity: 0 },
  { scale: 1, opacity: 1 },
  0.2
);

// Timeline for head & glasses
let tlHead = new TimelineMax();
tlHead.set(head, { opacity: 0, scale: 1.3 });
tlHead.set(glasses, { opacity: 0, scale: 1.3 });
tlHead.delay(1.5);
tlHead.to(head, 0.5, { opacity: 1, scale: 1 });
tlHead.to(glasses, 0.5, { opacity: 1, scale: 1 });

Conclusion

With just a few lines of JavaScript and the GreenSock library you can build complex SVG animations easily. Combining TimelineMax, Tween and staggerFromTo() produces flowing transitions that look impressive even with more complex logos.

One particular advantage of GSAP: performance stays stable even with several animations running in parallel – perfect for interactive websites and brand motion projects.

FAQs on SVG Logo Animation

What is GSAP?

GSAP stands for GreenSock Animation Platform – a powerful JavaScript library for performant web animation, ideal for SVG, canvas and DOM elements.

Do I need jQuery for GSAP?

No. GSAP is entirely independent of jQuery and can be used with plain JavaScript.

Is GSAP free?

Yes, the core of GSAP is free and open source. Only special plugins such as MorphSVG or SplitText require a club membership.

How can I start the animation on scroll?

Use GreenSock’s ScrollTrigger plugin to fire animations when specific scroll positions are reached.

Can I use GSAP with React or Vue?

Yes – GSAP integrates smoothly with modern frameworks, usually through hooks or lifecycle methods.