How to create mousemove parallax effects using HTML CSS & Javascript ? Last Updated : 23 Jul, 2025 Comments Improve Suggest changes 5 Likes Like Report In this article, we will learn to create a Mousemove parallax effect using CSS and JavaScript. In the Mousemove parallax effect, an image moves in a different direction at a different speed when we move the cursor. Parallax effects are used to make the website more attractive and increase the interactivity level of the website. The parallax effect is a way to scroll or move the foreground & background images at different speeds in different directions. We can use either of the combination ie, a text with an image or an image with an image, to create the parallax effect. Approach: In the <body> tag, create a <div> tag to assign some images on which the parallax effect is to be applied, and assign a class name and value attribute to each image that is responsible for the amount of shifting of the image.For the CSS stylings, add some CSS properties in the style tag such as position and size of images.We have taken the help of JavaScript to implement the parallax effect. In the snippet given under the script tag, we have created a function parallax that uses the class name of the img tag to get the value for positioning and shifting purposes.Example: In this step, we will create a movemouse parallax effect using the above approach. HTML <!-- Filename:index.html --> <!DOCTYPE html> <html lang="en"> <head> <style> * { margin: 0; padding: 0; box-sizing: border-box; font-family: sans-serif; } body { background-color: rgb(102, 189, 16); } .mouse_move { position: relative; width: 100%; height: 100vh; overflow: hidden; display: flex; justify-content: center; align-items: center; } .mouse_move h2 { position: relative; font-size: 100px; color: white; } .mouse_move img { position: absolute; } #img1 { top: 80px; left: 80px; height: 250px; width: 250px; } #img2 { bottom: 80px; right: 80px; height: 250px; width: 250px; } </style> <title>Parallax</title> </head> <body> <div class="mouse_move"> <img id="img1" src= "https://media.geeksforgeeks.org/wp-content/uploads/20210101144014/gfglogo.png" class="mouse" value="5" /> <h2>GeeksforGeeks</h2> <img id="img2" src= "https://media.geeksforgeeks.org/wp-content/cdn-uploads/20190710102234/download3.png" class="mouse" value="-5" /> </div> <script type="text/javascript"> document.addEventListener("mousemove", parallax); function parallax(event) { this.querySelectorAll(".mouse").forEach((shift) => { const position = shift.getAttribute("value"); const x = (window.innerWidth - event.pageX * position) / 90; const y = (window.innerHeight - event.pageY * position) / 90; shift.style.transform = `translateX(${x}px) translateY(${y}px)`; }); } </script> </body> </html> Output:From the above example, you can see that when we move the cursor from one direction to another the images start floating or shifting. Create Quiz Comment A anuragsingh1022 Follow 5 Improve A anuragsingh1022 Follow 5 Improve Article Tags : JavaScript Web Technologies JavaScript-Projects Explore JavaScript BasicsIntroduction to JavaScript4 min readVariables and Datatypes in JavaScript6 min readJavaScript Operators5 min readControl Statements in JavaScript4 min readArray & StringJavaScript Arrays7 min readJavaScript Array Methods7 min readJavaScript Strings5 min readJavaScript String Methods9 min readFunction & ObjectFunctions in JavaScript5 min readJavaScript Function Expression3 min readFunction Overloading in JavaScript4 min readObjects in JavaScript4 min readJavaScript Object Constructors4 min readOOPObject Oriented Programming in JavaScript3 min readClasses and Objects in JavaScript4 min readWhat Are Access Modifiers In JavaScript ?5 min readJavaScript Constructor Method7 min readAsynchronous JavaScriptAsynchronous JavaScript2 min readJavaScript Callbacks4 min readJavaScript Promise4 min readEvent Loop in JavaScript4 min readAsync and Await in JavaScript2 min readException HandlingJavascript Error and Exceptional Handling6 min readJavaScript Errors Throw and Try to Catch2 min readHow to create custom errors in JavaScript ?2 min readJavaScript TypeError - Invalid Array.prototype.sort argument1 min readDOMHTML DOM (Document Object Model)8 min readHow to select DOM Elements in JavaScript ?3 min readJavaScript Custom Events4 min readJavaScript addEventListener() with Examples9 min readAdvanced TopicsClosure in JavaScript4 min readJavaScript Hoisting6 min readScope of Variables in JavaScript3 min readJavaScript Higher Order Functions7 min readDebugging in JavaScript4 min read Like