Live preview · fully interactive
The prompt
Build a full-viewport crosshair cursor with live coordinates. ## Look A 1px horizontal line and a 1px vertical line in rgba(196,181,253,0.85). Coordinates sit bottom-right in 12px tabular nums, color #c4b5fd. Page #08080d. ## Behavior Each frame set the horizontal line’s top and the vertical line’s left from the pointer. Print rounded x, y. ## Design tokens - Lines rgba(196,181,253,0.85); readout #c4b5fd; page #08080d. ## Motion - Position updates every frame. Idle orbit until the first pointer move. ## Constraints - Single self-contained HTML file. No libraries. - Honor prefers-reduced-motion: reduce by skipping the loop and leaving a readable static frame - Readable at 390px width with no horizontal page scroll
The code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { min-height: 100%; }
body {
background: #08080d; color: #f2f2f7; font-family: Inter, system-ui, sans-serif;
min-height: 100vh; overflow: hidden;
}
.hint { position: absolute; left: 16px; top: 16px; z-index: 5; font-size: 11px; letter-spacing: 0.14em; text-transform: uppercase; color: #8a8a99; }
#hx, #hy { position: fixed; background: rgba(196,181,253,0.85); pointer-events: none; } #hx { left: 0; right: 0; height: 1px; } #hy { top: 0; bottom: 0; width: 1px; } #readout { position: fixed; right: 16px; bottom: 16px; font-variant-numeric: tabular-nums; font-size: 12px; color: #c4b5fd; }
@media (max-width: 420px) {
.hint { font-size: 10px; letter-spacing: 0.08em; }
}
@media (prefers-reduced-motion: reduce) {
*, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition: none !important; }
}
</style>
</head>
<body>
<p class="hint">Crosshair</p><div id="hx"></div><div id="hy"></div><p id="readout">0, 0</p>
<script>
var reduce = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
var pointer = { x: window.innerWidth / 2, y: window.innerHeight / 2 };
var userMoved = false;
window.addEventListener("pointermove", function (e) {
userMoved = true;
pointer.x = e.clientX;
pointer.y = e.clientY;
});
function idlePointer(now) {
if (userMoved || reduce) return;
pointer.x = window.innerWidth * (0.5 + Math.cos(now / 700) * 0.28);
pointer.y = window.innerHeight * (0.5 + Math.sin(now / 900) * 0.2);
}
var hx = document.getElementById("hx");
var hy = document.getElementById("hy");
var readout = document.getElementById("readout");
function frame(now) {
idlePointer(now);
hx.style.top = pointer.y + "px";
hy.style.left = pointer.x + "px";
readout.textContent = Math.round(pointer.x) + ", " + Math.round(pointer.y);
if (!reduce) requestAnimationFrame(frame);
}
requestAnimationFrame(frame);
</script>
</body>
</html>About this effect
One horizontal and one vertical 1px line track the pointer across the viewport, with coordinates in the corner. Aimed at developer tools and design-system pages.