# How to add a GSAP animation

<figure><img src="https://330243581-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FTep4EGj6hSC54ozHujyK%2Fuploads%2Fgit-blob-981d6c48deedcd3a58a80830fab871117e8c043a%2Fgsap.png?alt=media" alt=""><figcaption></figcaption></figure>

## Embed GSAP library on the page

1. Add HTML [Embed Component](https://docs.webstudio.is/university/core-components/html-embed) to the canvas
2. Activate "[Client Only](https://docs.webstudio.is/core-components/html-embed#client-only)" setting
3. Optionally activate "[Run script on canvas](https://docs.webstudio.is/core-components/html-embed#run-script-on-canvas)" setting
4. Open GSAP official [installation instruction](https://gsap.com/docs/v3/Installation)
5. Copy the scripts into HTML Embed Code in Settings

### Example

```html
<script defer src="https://cdn.jsdelivr.net/npm/gsap@3.12.5/dist/gsap.min.js"></script>
<script defer src="https://cdn.jsdelivr.net/npm/gsap@3.12.5/dist/Flip.min.js"></script>
<script type="module">
  gsap.registerPlugin(Flip);
  gsap.fromTo(".animation", {opacity: 0}, {
    opacity: 1, 
    duration: 1, 
    stagger: 0.1, 
    ease: "power2.inOut"
  });  
</script>
```

## Q\&A

### How to reuse the animation on multiple pages?

You can reuse the animation using [Slot component](https://docs.webstudio.is/core-components/html-embed#how-to-reuse-your-custom-code-across-multiple-web-pages)

### Can I use the Custom Code from project settings to include GSAP on all pages?

While you can add the library in the HEAD in project settings, this HTML won't run in preview, so you can't test inside the builder. Additionally, if you use async or defer attributes, there is no guarantee that your HTML Embed scripts on the page won't run before the library is loaded. If you don't use defer or async attributes, you will slow down your site by blocking the rendering until the library is loaded.

### Identifier 'x' has already been declared

Learn more about script scope [here](https://docs.webstudio.is/core-components/html-embed#avoid-creating-global-variables).

## Demo

[Preview Link](https://simple-gsap-demo.wstd.io/)\
[Builder Link](https://apps.webstudio.is/builder/623cdb40-24bb-4809-a610-145b6eefcf21?authToken=d0544921-f4bb-4697-a0d8-2efd2a0c4a11\&mode=preview)

## Related

* [Animations](https://docs.webstudio.is/university/foundations/animations) – Built-in animation capabilities in Webstudio
* [HTML Embed](https://docs.webstudio.is/university/core-components/html-embed) – Add custom scripts and code to your pages
* [Project settings](https://docs.webstudio.is/university/foundations/project-settings) – Add global scripts in the custom code section
* [Variables](https://docs.webstudio.is/university/foundations/variables) – Use variables for dynamic animation values
