Topics Covered in This JavaScript Tutorial:
Animating SVG, Transform Origin, Stagger: Animating Multiple Elements from a Single Tween
Exercise Preview

The exercise uses the GSAP-SVG-Stagger folder with svg-stagger.html file. The SVG code is embedded directly in HTML rather than using an img tag, allowing access to individual elements for animation.
Exercise Overview
SVG animations represent one of the most powerful yet underutilized techniques in modern web development. In this exercise, you'll master the art of animating Scalable Vector Graphics while discovering GSAP's sophisticated stagger property—a feature that transforms complex multi-element animations into elegant, single-line solutions.
The stagger technique you'll learn here is particularly valuable for creating professional loading sequences, interactive logos, and dynamic user interface elements that can significantly enhance user engagement and brand perception.
Getting Started
- For this exercise we'll be working with the GSAP-SVG-Stagger folder located in Desktop > Class Files > JavaScript Class. Open that folder in your code editor if it allows you to (like Visual Studio Code does).
- In your code editor, open svg-stagger.html from the GSAP-SVG-Stagger folder.
Preview svg-stagger.html in a browser.
You'll recognize the Noble Desktop logo from previous exercises, but notice the HTML structure is fundamentally different. Instead of treating the logo as a single image, we've prepared it for granular animation control—allowing us to animate individual letters, shapes, and elements within the logo independently.
Back in your code editor, examine the HTML structure carefully. Understanding this setup is crucial for professional SVG animation work:
Rather than using an img tag like previous exercises, we've embedded the complete SVG code directly into our HTML. This inline approach is essential for accessing and animating individual SVG elements—a technique commonly used in production environments for interactive graphics.
Note: This SVG code was generated by professional design tools such as Adobe Illustrator, Figma, Adobe XD, or Sketch. Modern design-to-code workflows rely heavily on this export capability.
- Throughout the SVG, you'll encounter
<g>tags, which represent groups—the organizational building blocks of complex SVG graphics. These groups were strategically created and named in the design application, automatically converting to unique IDs during SVG export. Study the hierarchical structure of the grouped elements within the SVG logo:
—Noble Desktop (parent container)
—noble (individual letters of "noble")
—desktop (individual letters of "desktop")—n-background (the rounded rectangle behind the icon)
—n (the colored letter elements)This logical grouping enables sophisticated animation control and is a hallmark of well-structured SVG graphics.
Project Setup Process
Open Project Folder
Navigate to Desktop > Class Files > JavaScript Class and open the GSAP-SVG-Stagger folder in your code editor
Examine SVG Structure
Review the embedded SVG code with grouped elements using g tags and IDs like 'Noble Desktop', 'noble', 'desktop', 'n-background', and 'n'
Preview in Browser
Open svg-stagger.html in a browser to see the initial state of the Noble Desktop logo before animation
Creating a Timeline & Solving Display Constraints
Before diving into animations, we need to establish our GSAP timeline and address a common SVG animation challenge: element clipping during transforms.
GSAP has already been linked to this file. In the script tag at the bottom, add the following code to instantiate a new timeline:
<script> let tl = gsap.timeline(); </script>Let's immediately identify a critical issue with SVG animations: elements will be cropped when they extend beyond the SVG container boundaries. To demonstrate this, we'll use GSAP's .set method, which instantly applies properties without animation—perfect for initial positioning and debugging.
Add the following code to move the text group:
<script> let tl = gsap.timeline(); tl.set('#Noble Desktop', {x:50}) </script>Save and reload the page in the browser.
Notice how the right side of desktop is truncated—this is SVG's default overflow behavior cutting off content that extends beyond the container bounds. This is a common challenge in production SVG animation that we'll resolve with CSS.
- Back in your code editor, open main.css from the css folder.
In the #logo rule, add the overflow property:
#logo { overflow: visible; width: 100%; max-width: 700px; height: auto; }Save and reload the page in the browser.
Perfect! The entire logo is now visible, including elements that extend beyond the original SVG boundaries. This CSS technique is essential for professional SVG animations.
Return to svg-stagger.html and replace the .set method with this entrance animation:
<script> let tl = gsap.timeline(); tl.from('#Noble Desktop', {duration:.4, scale:0, x:-5}) </script>Save and reload the page.
The text now scales up from zero while sliding slightly from left to right. However, notice the scaling originates from the top-left corner, which feels mechanically awkward. Professional animations require precise control over transformation origins.
Mastering Transform Origin
Transform origin determines the anchor point for scale, rotation, and skew transformations. Mastering this property is crucial for creating polished, professional animations.
Add the transform origin property to control the scaling behavior:
.from('#Noble Desktop', {duration:.4, scale:0, transformOrigin:'left center', x:-5})Professional tip:
transformOriginaccepts multiple value formats for maximum flexibility:
• Keywords:'left center'
• Percentages:'0% 50%'
• Pixels:'0px 25px'Save and reload the page.
The animation now scales from the vertical center of the left edge, creating a much more natural and visually pleasing entrance effect. This attention to transformation details separates amateur animations from professional-grade work.
Transform Origin Values
| Feature | Format | Example |
|---|---|---|
| Keywords | left center | right top |
| Percentages | 0% 50% | 100% 0% |
| Pixels | 10px 20px | 0px 50px |
Stagger: Orchestrating Multiple Elements with Precision
Now we'll explore GSAP's stagger functionality—one of its most powerful features for creating sophisticated multi-element animations with minimal code. This technique is extensively used in modern web applications for loading sequences, menu animations, and interactive interfaces.
The SVG's g (group) elements provide the perfect structure for staggered animations. Within our Noble Desktop parent group, we have two child groups: noble and desktop, each containing individual letter elements.
Target the direct child groups using CSS's direct descendant selector
>:.from('#Noble Desktop > g', {duration:.4, scale:0, transformOrigin:'left center', x:-5})Save and reload the page.
Both words animate simultaneously. While visually interesting, we want sequential animation to create more dynamic visual flow.
Add the stagger property to create sequential timing:
.from('#Noble Desktop > g', {duration:.4, scale:0, stagger:1, transformOrigin:'left center', x:-5})Save and reload the page.
Now the first word animates, followed by a 1-second delay, then the second word. This demonstrates stagger's basic functionality, but we can create far more impressive effects by animating individual letters.
Reduce the stagger timing for rapid-fire animation:
.from('#Noble Desktop > g', {duration:.4, scale:0, stagger:0.03, transformOrigin:'left center', x:-5})Target all nested elements using the wildcard selector:
.from('#Noble Desktop *', {duration:.4, scale:0, stagger:0.03, transformOrigin:'left center', x:-5})The asterisk (*) is a CSS wildcard that selects every element within the Noble Desktop group, giving us granular control over individual letters.
Save and reload the page.
Excellent! Each letter now animates independently with a subtle 0.03-second delay, creating a sophisticated wave effect across the text. This single line of code replaces what would otherwise require dozens of individual animations.
Add a back ease for enhanced visual appeal:
.from('#Noble Desktop *', {duration:.4, scale:0, stagger:0.03, transformOrigin:'left center', x:-5, ease:'back.out'})Important note: Stagger functionality works with any DOM elements, not just SVG. You can apply this technique to HTML elements, images, cards, buttons—any collection of elements that benefits from sequential animation.
Save and reload the page.
The back ease adds a delightful bounce effect, giving the animation personality and professional polish. Easing curves are fundamental to creating animations that feel natural and engaging rather than mechanical.
Creating Perpetual Animation Loops
For logo animations and loading sequences, continuous loops with thoughtful pacing can enhance brand presence without becoming distracting.
Configure the timeline for infinite repetition with breathing room between cycles:
let tl = gsap.timeline({repeat:-1, repeatDelay:1});Save and reload the page.
The animation now cycles continuously with a 1-second pause between iterations, allowing viewers to appreciate the completed logo before the next animation cycle begins.
Completing the Logo Animation System
Professional logo animations require cohesive timing and visual hierarchy. Let's animate the remaining logo elements with strategic sequencing.
Add the background rectangle animation that follows the text sequence:
.from('#Noble Desktop *', {duration:.4, scale:0, stagger:0.03, transformOrigin:'left center', x:-5, ease:'back.out'}) .from('#n-background', {duration:.3, scale:0, transformOrigin:'right center', ease:'back.out'})Save and reload the page.
The black rectangle now appears after the text animation completes, scaling from the right center—creating visual balance with the left-originated text animation.
Complete the sequence by animating the colored icon elements:
.from('#Noble Desktop *', {duration:.4, scale:0, stagger:0.03, transformOrigin:'left center', x:-5, ease:'back.out'}) .from('#n-background', {duration:.3, scale:0, transformOrigin:'right center', ease:'back.out'}) .from('#n *', {duration:.2, scale:0, transformOrigin:'center', stagger:0.03, ease:'back.out'})Save and reload the page.
The logo animation is now complete. Each colored element of the 'n' icon appears sequentially in a rapid, polished sequence. This demonstrates GSAP's power: a complex, multi-element professional animation achieved with just three lines of code.
Advanced Timing Control with Position Parameters
Professional animators fine-tune timing relationships between animation sequences to create optimal flow and pacing. GSAP's position parameters provide precise control over when animations begin relative to each other.
Optimize the pacing by overlapping the background animation with the text sequence:
.from('#n-background', {duration:.3, scale:0, transformOrigin:'right center', ease:'back.out'}, '-=0.3')The
-=0.3parameter starts this animation 0.3 seconds before the previous animation completes, creating smooth transitions and eliminating dead time in the sequence.Save and reload the page.
The refined timing creates a more fluid, professional animation flow. This overlapping technique is essential for creating dynamic sequences that maintain viewer engagement without feeling rushed or sluggish.