Skip to main content


Show more

Cursor Animation With Hover Effect Using GSAP | HTML, CSS And GSAP


Cursor Animation With Hover Effect Using GSAP Using HTML, CSS And GSAP

You must have seen the portfolio of some developer or have seen websites with animation. On that developers change the mouse cursor and design it accordingly. Similarly, we will also create a mouse cursor here, which will become bigger than the normal size on hovering over a button and the background of the mouse will also change. We have also created this type of mouse cursor using JavaScript's Pointerjs plugin. But the hover effect was not created in that cursor. Pointerjs plugin was used which slows down the response of the website.

We hope you have understood the concept of this mouse cursor animation. Now let us move on to the techniques that we are using to achieve this goal. As always HTML and CSS is mandatory. Javascript will be used to create this cursor animation and GSAP will also be used.


<!DOCTYPE html>
  <title>Cursor Animation With Hover Effect Using GSAP | Rustcode</title>   
  <link rel="stylesheet" href="style.css">


    main content.


02. HTML

<!DOCTYPE html>
 <title>Cursor Animation With Hover Effect Using GSAP | Rustcode</title>
 <link rel="stylesheet" href="style.css">


<div class="cursor"></div>

<div class="container">
  <button>Hover me</button>

<script src="script.js"></script>

Now it's time to add the animation library GSAP. You can visit the official website of Greensock to read the documentation.

<script src=""></script>

03. CSS

  @import url(';600;700');

    margin: 0px;
    padding: 0px;
    font-family: "Poppins", sans-serif;
    font-weight: 700;
    box-sizing: border-box;
    cursor: none;

    background: #E8DDB5;
    display: flex;
    height: 100vh;
    justify-content: center;
    align-items: center;

    border: 0px;
    outline: 0px;
    background: #745296;
    padding: 16px 32px;
    box-shadow: rgba(0, 0, 0, 0.2) 0px 10px 20px 0px;
    margin: 1rem 0;
    color: white;

    width: 50px;
    height: 50px;
    border: 3px solid white;
    border-radius: 50%;
    position: fixed;
    pointer-events: none;
    transform-origin: 100% 100%;
    transform: translate(-50%, -50%);
    mix-blend-mode: difference;

    background: white;


let mouseCursor = document.querySelector(".cursor");
let btn = document.querySelectorAll("button");

window.addEventListener("mousemove", cursor);

function cursor(e){, 0.4, {
    x: e.clientX,
    y: e.clientY

btn.forEach(link => {
  link.addEventListener("mouseover", ()=>{
    mouseCursor.classList.add("scale-cursor");, 0.4, {
      scale: 2

  link.addEventListener("mouseleave", ()=>{
    mouseCursor.classList.remove("scale-cursor");, 0.4, {
      scale: 1

05. Youtube Video