Snake Like Effect using CSS and JavaScript Last Updated : 05 May, 2025 Comments Improve Suggest changes Like Article Like Report In this article, we will see how to create a Snake Like Effect by using CSS and JavaScript.CDN Link: Include the following GSAP library in your HTML code.<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.6.0/gsap.min.js"></script>Approach :We have taken a div tag named snake which is an instance of the full snake. We have taken circle, we can take another shape by using simple CSS.We have created more divs to give the length of the snake. We can include more div tags to increase its length.document.body.addEventListener("mousemove"): This function in JavaScript attaches a moving mouse event to the document. When the user moves the mouse pointer anywhere in the document, the event which is being mentioned occurs.e.clientX: Get the horizontal coordinate.e.clientY: Get the vertical coordinate.stagger :For delay in animation (0.05 sec), we can see the snake.gsap.to(".snake"): It will track the snake with reference to pointer coordinates.Example: HTML <!DOCTYPE html> <html> <head> <style type="text/css"> /* Area part for snake */ </style> </head> <body> <div class="area"> <!-- You can add more divs for a long snake--> <div class="snake"></div> <div class="snake"></div> <div class="snake"></div> <div class="snake"></div> <div class="snake"></div> <div class="snake"></div> <div class="snake"></div> <div class="snake"></div> <div class="snake"></div> <div class="snake"></div> </div> <!-- GSAP Library --> <script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.6.0/gsap.min.js"> </script> <!-- JavaScript Code for mouse event --> <script type="text/javascript"> document.body.addEventListener("mousemove", e => { gsap.to(".snake", { x : e.clientX, y : e.clientY, stagger : -0.05, }) }) </script> </body> </html> CSS .area { width: 80px; height: 80px; position: relative; } /* Designing of a part of snake (here circle) */ .area .snake { position: absolute; top: 0; left: 0; width: 100%; height: 100%; background: rgb(3, 171, 15); border: 2px solid white; border-radius: 50%; } Output:As you can see from the above output, we have created a snake that follows our mouse pointer making it look like a Snake-like effect. Comment More infoAdvertise with us Next Article Snake Like Effect using CSS and JavaScript harshit17 Follow Improve Article Tags : JavaScript Web Technologies JavaScript-Projects Similar Reads Self-Typing Text Effect using CSS & JavaScript Self-Typing Text Effect is a type of effect in which all the alphabets of the text are revealed one by one, one after the other to give the look and feel of being typed on the screen by themselves. Even though this is a basic text effect, it is still eye-capturing and effective animation. This anima 5 min read Create a snake game using HTML, CSS and JavaScript Snake Game is a single-player game where the snake gets bigger by eating the food and tries to save itself from the boundary of the rectangle and if the snake eats their own body the game will be over.Game Rules:If the snake goes out of the boundary or eats its own body the game will be over.Prerequ 4 min read Text Typing Animation Effect using HTML CSS and JavaScript To create a text-typing animation effect, we will use a combination of HTML structure, CSS animations, and JavaScript logic to create the typing and deleting text like effect.HTML<!-- index.html --> <html> <head> <link rel="stylesheet" href="styles.css"> </head> <bod 2 min read Design a Letter Hover Effect using HTML CSS and JavaScript In this article, we will learn to implement the bouncing letter hover effect using simple HTML, CSS, and JavaScript. HTML is used to create the structure of the page, CSS is used to set the styling and JavaScript is used for animation. Approach to Create the Bouncing Letter Hover EffectHTML Code: To 2 min read How to make Animated Click Effect using HTML CSS and JavaScript ? In this article, we will see how to make an Animated Click Effect using HTML CSS, and JavaScript. We generally see animations on modern websites that are smooth and give users a good experience. Here, we will see when the user clicks on the button only then some animation would appear. The animation 3 min read script.aculo.us SlideDown Effect In this article we will demonstrate the effect of SlideDown by using JavaScript library called script.aculo.us having smooth transition from one to another. We can adjust the duration of the effect as well. Syntax : Effect.SlideDown('id_of_element'); Effect.SlideDown('id_of_element', { duration: 3.0 2 min read Dancing Keys Effect using HTML and CSS The dancing keys effect is a type of text-animation effect that can be implemented using CSS. In this effect, each letter is given the form of a keyboard key and then animations are applied to move it along either X-axis or Y-axis. This effect is also known as the Jumping Key effect or Piano Key eff 4 min read How to Add Onclick Effect using CSS ? In this article, we will see how to add onclick effect using CSS. To add the onclick effect using CSS, we can use :active pseudo selector. When an element is clicked, the onclick JavaScript event is launched. JavaScript is required to add an event listener to the HTML element and then run some code 2 min read Create the marquee text effect using JavaScript In this article, we will be creating marquee text using JavaScript. This effect can be achieved using the <marquee> tag, but the marquee has been deprecated and the new websites do not use this tag. Still some browsers support this tag but to be on the safe side you should not use this tag. He 3 min read script.aculo.us SlideUp Effect In this article, we will demonstrate the visual effect of SlideUp option by using JavaScript library called script.aculo.us having smooth transition from one to another. We can adjust the duration of the effect as well. Syntax : Effect.SlideUp('id_of_element'); or Effect.SlideUp('id_of_element', { d 2 min read Like