Adding an interactive parallax background to a webpage

This tutorial shows you how to add interactive parallax backgrounds to your website. You can move your mouse around and see the layers move around like below.

Check out the demo here


We’ll not be using any libraries to build this feature, just vanilla javascript. In this example I’ll be showing you how to write this as a react component but the overall workings are the same and you can expect this to work in plain javascript.

And later on you can use this component like

Make sure you order the images in that order so they stack on top and don’t cover each other. Also you’ll have to use PNG or some other formats which has transparent parts. If you want the asset files, you can find them in this github repo.

NPM package

If you’d like, I’ve already made an npm package of this component. There is also a working example in the github repo.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Basith Kunimal

Web Developer. Biker. Armchair Historian. German language student.