Interactive Dot Grid
A rippling dot grid background where dots swell, glow cyan and push away around your cursor.
Preview and code
index.html
<!--
MIT License
Copyright (c) 2026 Suraj Maurya
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions
of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
-->
<div class="ds" data-dot="rgba(255,255,255,0.15)" data-accent="#00F0FF" data-size="1.5" data-spacing="22" data-radius="180" data-distortion="0.35" data-scale="2.2" data-wave="0.25" data-speed="1">
<canvas aria-hidden="true"></canvas>
<div class="ds-over" aria-hidden="true"></div>
<div class="ds-copy"><span>Realtime</span><h2>Signals, not noise</h2><p>Move your cursor across the grid.</p></div>
</div>
styles.css
.ds{position:relative;width:100%;height:calc(100vh - 40px);min-height:240px;overflow:hidden;border-radius:16px;background:#050507;font-family:Inter,system-ui,-apple-system,"Segoe UI",sans-serif}
.ds canvas{position:absolute;inset:0;display:block;width:100%;height:100%}
.ds-over{position:absolute;inset:0;background:radial-gradient(ellipse at center,transparent 35%,rgba(5,5,7,.85) 100%);pointer-events:none}
.ds-copy{position:relative;z-index:1;display:flex;flex-direction:column;align-items:center;justify-content:center;height:100%;padding:20px;text-align:center;pointer-events:none}
.ds-copy span{padding:4px 10px;border:1px solid rgba(0,240,255,.3);border-radius:999px;color:#67e8f9;font:11px ui-monospace,SFMono-Regular,Menlo,monospace;letter-spacing:.14em;text-transform:uppercase}
.ds-copy h2{margin:14px 0 6px;color:#fff;font-size:clamp(28px,6vw,52px);font-weight:700;letter-spacing:-.035em}
.ds-copy p{margin:0;color:#a1a1aa;font-size:14px}
script.js
(function(){
function parse(c){var cv=document.createElement('canvas');cv.width=cv.height=1;var x=cv.getContext('2d');x.fillStyle=c;x.fillRect(0,0,1,1);var d=x.getImageData(0,0,1,1).data;return[d[0],d[1],d[2],d[3]/255];}
document.querySelectorAll('.ds').forEach(function(box){
var d=box.dataset,cv=box.querySelector('canvas'),ctx=cv.getContext('2d'),dot=parse(d.dot||'rgba(255,255,255,.15)'),acc=parse(d.accent||'#00F0FF'),sz=+d.size||1.5,sp=+d.spacing||22,R=+d.radius||180,dist=+d.distortion||.35,mxs=+d.scale||2.2,wave=+d.wave||.25,speed=+d.speed||1,W=0,H=0,pts=[],tgt={x:-9999,y:-9999},cur={x:-9999,y:-9999},t=0,last=performance.now(),vis=true,raf=null,reduce=matchMedia('(prefers-reduced-motion: reduce)').matches;
function size(){var dpr=Math.min(devicePixelRatio||1,2);W=box.offsetWidth;H=box.offsetHeight;if(!W||!H)return;cv.width=W*dpr;cv.height=H*dpr;ctx.setTransform(dpr,0,0,dpr,0,0);pts=[];var cols=Math.ceil(W/sp)+1,rows=Math.ceil(H/sp)+1,ox=(W-(cols-1)*sp)/2,oy=(H-(rows-1)*sp)/2;for(var j=0;j<rows;j++)for(var i=0;i<cols;i++)pts.push([ox+i*sp,oy+j*sp,i,j]);draw();}
function sm(e){return e*e*(3-2*e);}
function draw(){ctx.clearRect(0,0,W,H);for(var k=0;k<pts.length;k++){var p=pts[k],x=p[0],y=p[1]+(reduce?0:Math.sin(p[2]*.15+p[3]*.15+t*1.5)*4*wave),dx=x-cur.x,dy=y-cur.y,dd=Math.sqrt(dx*dx+dy*dy),pr=1-sm(Math.min(1,dd/R));if(dd>.001){x+=dx/dd*pr*24*dist;y+=dy/dd*pr*24*dist;}
var r=sz*(1+pr*(mxs-1)),c0=dot[0]+(acc[0]-dot[0])*pr,c1=dot[1]+(acc[1]-dot[1])*pr,c2=dot[2]+(acc[2]-dot[2])*pr,a=dot[3]+(acc[3]-dot[3])*pr;ctx.fillStyle='rgba('+(c0|0)+','+(c1|0)+','+(c2|0)+','+a.toFixed(3)+')';ctx.beginPath();ctx.arc(x,y,r,0,6.2832);ctx.fill();}}
function loop(now){if(!vis){raf=null;return;}var dt=Math.min(.05,(now-last)/1000);last=now;t+=dt*speed;if(tgt.x<-9000){cur.x=-9999;cur.y=-9999;}else{if(cur.x<-9000){cur.x=tgt.x;cur.y=tgt.y;}cur.x+=(tgt.x-cur.x)*.12;cur.y+=(tgt.y-cur.y)*.12;}draw();raf=requestAnimationFrame(loop);}
box.addEventListener('pointermove',function(e){if(reduce)return;var r=box.getBoundingClientRect(),z=r.width/box.offsetWidth||1;tgt.x=(e.clientX-r.left)/z;tgt.y=(e.clientY-r.top)/z;});
box.addEventListener('pointerleave',function(){tgt.x=-9999;tgt.y=-9999;});
size();if(window.ResizeObserver)new ResizeObserver(size).observe(box);else addEventListener('resize',size);
if(window.IntersectionObserver)new IntersectionObserver(function(es){vis=es[0].isIntersecting;if(vis&&!raf&&!reduce){last=performance.now();raf=requestAnimationFrame(loop);}}).observe(box);
if(!reduce)raf=requestAnimationFrame(loop);
});
})();
About
A living dot-grid background for hero sections. Evenly spaced dots ripple in a slow diagonal wave, and as your pointer moves they bulge outward from it, grow up to twice their size and shift from soft white to a bright accent colour, easing smoothly behind the cursor. A gentle vignette keeps edges calm so text on top stays readable. Dot colour, accent, size, spacing, cursor radius, distortion, wave strength and speed are all adjustable. It renders crisply on high-DPI screens, pauses off-screen and holds a still grid for reduced motion.