> For the complete documentation index, see [llms.txt](https://docs.webstudio.is/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.webstudio.is/university/how-tos/how-to-add-a-gsap-animation.md).

# How to add a GSAP animation

Add GSAP animations to your Webstudio site with custom code.

<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&amp;token=5678dff6-3b96-45b9-a659-d4d869321d99" alt="HTML Embed settings with GSAP script code in the Code editor"><figcaption></figcaption></figure>

## Embed GSAP library on the page

1. Add HTML [Embed Component](https://docs.webstudio.is/university/core-components/html-embed.md) to the canvas
2. Activate "[Client Only](https://docs.webstudio.is/university/core-components/html-embed.md#client-only)" setting
3. Optionally activate "[Run script on canvas](https://docs.webstudio.is/university/core-components/html-embed.md#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/university/core-components/html-embed.md#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/university/core-components/html-embed.md#avoid-creating-global-variables).

## Demo

[Preview the GSAP demo](https://simple-gsap-demo.wstd.io/).

## Related

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


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.webstudio.is/university/how-tos/how-to-add-a-gsap-animation.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
