💡 Glowing Dots Background
Bring your UI to life with Glowing Graph Background, a high-performance React component that creates a mesmerizing, interactive grid glow effect! 🔥✨ As users hover, random grid cells illuminate with neon colors, smoothly fading out for a futuristic, cyberpunk-inspired aesthetic. Perfect for dashboards, landing pages, hero sections, and modern web designs, this Next.js & Tailwind CSS-powered effect adds a dynamic, lightweight animation without compromising performance. Whether you're building a tech-inspired UI, a sci-fi interface, or an engaging user experience, this glowing grid background makes every interaction feel next-level. 🚀💡
Preview
Follow below steps 👇🏻
Install dependencies
1npm i framer-motion
Component
Create a file glowing-dots-background.tsx in your components folder and paste this code
1'use client';23import React, { useEffect, useRef, useState } from 'react';4import { motion } from 'framer-motion';56const GRID_SIZE = 30;7const FADE_DELAY = 1000;89type GlowingDotsBackgroundProps = {10children: React.ReactNode;11className?: string;12};1314const getRandomColor = () => {15const colors = ['#FF5733', '#33FF57', '#3357FF', '#FF33A8', '#FFD700', '#00FFFF'];16return `${colors[Math.floor(Math.random() * colors.length)]}77`;17};1819const GlowingDotsBackground = ({ children, className }: GlowingDotsBackgroundProps) => {20const divRef = useRef<HTMLDivElement>(null);21const activeCells = useRef<Set<number>>(new Set());22const [gridSize, setGridSize] = useState({ cols: 0, rows: 0 });23const [hoveredCells, setHoveredCells] = useState<number[]>([]);2425useEffect(() => {26if (!divRef.current) return;2728const updateGridSize = () => {29const height = divRef.current!.offsetHeight;30const width = divRef.current!.offsetWidth;31setGridSize({32rows: Math.ceil(height / GRID_SIZE),33cols: Math.ceil(width / GRID_SIZE)34});35};3637updateGridSize();38window.addEventListener('resize', updateGridSize);39return () => window.removeEventListener('resize', updateGridSize);40}, []);4142const handleMouseEnter = (index: number) => {43if (activeCells.current.has(index)) return;4445activeCells.current.add(index);46setHoveredCells((prev) => [...prev, index]);4748setTimeout(() => {49activeCells.current.delete(index);50setHoveredCells((prev) => prev.filter((i) => i !== index));51}, FADE_DELAY);52};5354return (55<div ref={divRef} className="h-full w-full flex items-center justify-center relative">56<div57id="glowing-dots-background"58style={{59gridTemplateColumns: `repeat(${gridSize.cols}, ${GRID_SIZE}px)`60}}61className="grid overflow-hidden h-full w-full"62>63{Array(gridSize.rows * gridSize.cols)64.fill(null)65.map((_, i) => (66<motion.div67key={'box' + i}68onMouseEnter={() => handleMouseEnter(i)}69animate={{70boxShadow: hoveredCells.includes(i) ? `1px 1px 20px 2px ${getRandomColor()}` : ''71}}72transition={{ duration: 0.3 }}73className={`h-[${GRID_SIZE}px] w-[${GRID_SIZE}px] border-[1px] rounded-full border-neutral-800`}74/>75))}76</div>7778<div79style={{ background: 'radial-gradient(circle at center, transparent, #000000)' }}80className="h-full w-full absolute pointer-events-none"81/>8283<div84className={`h-full w-full flex items-center pointer-events-none justify-center absolute top-0 left-0 ${className}`}85>86{children}87</div>88</div>89);90};9192export default GlowingDotsBackground;
Usage
1<GlowingDotsBackground className=" text-5xl font-extrabold text-white rounded-xl flex items-center justify-center h-full w-full">2Glowing Dots Background3</GlowingDotsBackground>
⭐️ Got a question or feedback?
Feel free to reach out!