DEV Community

Cover image for Custom cursor with Greensock
Dezigner Bay
Dezigner Bay

Posted on • Updated on

Custom cursor with Greensock

Hi guys, in this short tutorial, you're going to learn how to create an animated custom cursor with GSAP and basic HTML and CSS. Ok, then, what's this GSAP called?

What is GSAP ?

Greensock Animation Platform(GSAP) is a JavaScript library for creating high-performance animations. Animate CSS, SVG, canvas, React, Vue, WebGL, colors, strings, motion paths, generic objects...anything JavaScript can touch!.GSAP has been tested across all major web browsers – including legacy fares such as Internet Explorer. All browser-related tweaks and fallbacks have already been integrated into the platform.

Why GSAP ?
  • Crazy fast
  • Freakishly robust
  • Compatible
  • Animate anything
  • Lightweight and expandable
  • No dependencies
  • Advanced sequencing

Detailed information

Ok.let's start the coding then.


<!DOCTYPE html>
<html lang="en" >
  <meta charset="UTF-8">
  <title>Custom Cursor</title>
  <link href="style.css" rel="stylesheet">

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

<script src=""></script>
<script src="main.js"></script>
Enter fullscreen mode Exit fullscreen mode

The first thing you need to do is, add gsap.min.js to your index.html.To Install GSAP, you can use the following methods.

Screenshot (381)

after that, import style.css and main.js to your index.html.


*{cursor: none;}

  overflow: hidden;

    position: fixed;
    top: 0;
    left: 0;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background-color: #fff;
    z-index: 2000;
    user-select: none;
    pointer-events: none;

    position: fixed;
    top: 0;
    left: 0;
    width: 100px;
    height: 100px;
    background-color: #6eff00;
    border-radius: 50%;
    opacity: 0.7;
    user-select: none;
    pointer-events: none;
Enter fullscreen mode Exit fullscreen mode



var follow = document.querySelector('.follower');
var cur = document.querySelector('.cursor');

window.addEventListener('mousemove',e => {,0.2,{x:e.clientX,y:e.clientY});,0.9,{x:e.clientX,y:e.clientY});

Enter fullscreen mode Exit fullscreen mode
Enter fullscreen mode Exit fullscreen mode

Here, the gsap.set() methods always set the follower and the cursor centered on each other when we move the cursor.
Watch the Demo, then you can understand it clearly.,0.2,{x:e.clientX,y:e.clientY});
Enter fullscreen mode Exit fullscreen mode specifies the values to which the object is to be animated. Here,0.2 is the duration time of the cursor moves.

The 'clientX' property returns the horizontal mouse pointer coordinate when the mouse event is triggered.

The 'clientY' property returns the vertical mouse pointer coordinate when the mouse event is triggered.


So, hope you all like this tutorial, and don't forget to check out and subscribe my YouTube channel. There are very useful videos on my channel and that will be really helpful to your career in web development.

Top comments (2)

prowhiz profile image
Oscar Obians

What about adding interactions like scale the cursor when it hovers over a link or button element?

saikumr305 profile image
Rachakonda Sai kumar

Yeah, I am also struggling with that part.. instead of adding and removing classes on mouseenter and mouseleave events .. is there any other way of doing it?