css
body {
cursor: none;
}
.cursor {
position: absolute;
top: 0;
left: 0;
width: 20px;
height: 20px;
background-color: green;
border-radius: 50%;
pointer-events: none;
}
js
const cursor = document.querySelector(".cursor");
document.addEventListener("mousemove", function (e) {
cursor.style.left = e.clientX + "px";
cursor.style.top = e.clientY + "px";
});
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Custom Cursor</title>
<style>
body {
cursor: none; /* Hide the default cursor */
}
.cursor {
position: absolute;
top: 0;
left: 0;
width: 20px;
height: 20px;
background-color: green;
border-radius: 50%;
pointer-events: none;
}
</style>
</head>
<body>
<div class="cursor"></div>
<script>
const cursor = document.querySelector(".cursor");
document.addEventListener("mousemove", function (e) {
cursor.style.left = e.clientX + "px";
cursor.style.top = e.clientY + "px";
});
</script>
</body>
</html>