GSAP FLIP Plugin (Layout Animations Made Easy)
- FLIP plugin helps you animate between layout states smoothly when elements change position or size.
Introduction
The FLIP Plugin in GSAP makes it easy to animate layout changes that normally jump instantly.
FLIP stands for:
-
First
-
Last
-
Invert
-
Play
It is commonly used for:
-
Card reordering
-
Grid / gallery animations
-
Expanding & collapsing UI
-
Drag-and-drop effects
FLIP is an official plugin from GreenSock GSAP
-
The Problem FLIP Solves
Without FLIP:
-
Changing CSS layout = instant jump
-
Elements suddenly move or resize
With FLIP:
-
Layout changes animate smoothly
-
No manual position calculations
👉 Think of FLIP as “animate after DOM changes”.
-
Basic Concept (FLIP Explained Simply)
-
First – capture initial position
-
Last – change the layout (CSS / DOM)
-
Invert – calculate difference
-
Play – animate smoothly
GSAP handles all math for you.
-
Installation / Setup
<script src="https://unpkg.com/gsap@3/dist/gsap.min.js"></script>
<script src="https://unpkg.com/gsap@3/dist/Flip.min.js"></script>
gsap.registerPlugin(Flip);
const state = Flip.getState(".card");
// change layout here
container.classList.toggle("active");
Flip.from(state, {
duration: 0.6,
ease: "power2.inOut"
});
Parameters / Options
Option Meaning Example getState()Capture initial layout .cardfrom()Animate from old state — durationAnimation time 0.6easeMotion easing "power2.inOut"absolutePrevent layout shift true
Card Grid Reorder
const btn = document.querySelector("button");
btn.addEventListener("click", () => {
const state = Flip.getState(".item");
grid.classList.toggle("reorder");
Flip.from(state, {
duration: 0.7,
stagger: 0.05
});
});
Expand / Collapse Card
card.addEventListener("click", () => {
const state = Flip.getState(card);
card.classList.toggle("expanded");
Flip.from(state, { duration: 0.5 });
});
List Sorting Animation
const state = Flip.getState("li");
list.appendChild(list.children[0]);
Flip.from(state, {
duration: 0.5,
ease: "power1.inOut"
});
FLIP with Absolute Positioning
Flip.from(state, {
duration: 0.6,
absolute: true
});
Best Practices
-
Capture state before DOM change
-
Use
absolute:truefor complex layouts -
Combine with stagger for smooth flow
-
Use FLIP instead of manual transforms
-
Comparison
Method Use Case FLIP Plugin Layout transitions CSS transition Simple cases Transform math Complex & manual Auto Layout Limited control
Quick Summary
-
FLIP animates layout changes
-
No manual position calculation
-
Perfect for grids & UI
-
Smooth and professional
-
Beginner-friendly syntax
-