Learn how to create and animate sprite sheets for your games and web projects
A sprite sheet is like a comic strip or flip book - it contains multiple frames of an animation arranged in a grid. Instead of having separate image files for each frame, you put them all together in one image. This makes it easier to load and animate characters in games and websites.
Perfect for simple animations like a blinking eye or a bouncing ball. Four pictures arranged in a square give you a short, smooth loop.
Grid Layout
Real Example
Animated Version
2x2 Grid = 4 animation frames
Great for walking animations or more detailed movements. Nine pictures give you smoother motion and more personality in your character.
Grid Layout
Real Example
Animated Version
3x3 Grid = 9 animation frames
Perfect for complex animations like dancing, fighting moves, or detailed facial expressions. Sixteen frames create very smooth, professional-looking animations.
4x4 Grid = 16 animation frames
There are two main ways to animate sprite sheets: CSS and JavaScript. Both work by showing one frame at a time, but JavaScript gives you more control.
.sprite-animation { width: 64px; height: 64px; background-image: url('your-sprite-sheet.png'); animation: play 1s steps(9) infinite; } @keyframes play { 0% { background-position: 0 0; } 100% { background-position: -576px 0; } }
CSS steps() function jumps between frames instead of smoothly sliding. Good for simple animations.
function SpriteAnimation({ src, size = 64, speed = 150, gridSize = 3 }) { const [currentFrame, setCurrentFrame] = useState(0) const totalFrames = gridSize * gridSize useEffect(() => { const interval = setInterval(() => { setCurrentFrame((prev) => (prev + 1) % totalFrames) }, speed) return () => clearInterval(interval) }, [speed, totalFrames]) const row = Math.floor(currentFrame / gridSize) const col = currentFrame % gridSize return ( <div style={{ width: size, height: size, backgroundImage: `url(${src})`, backgroundSize: `${size * gridSize}px ${size * gridSize}px`, backgroundPosition: `-${col * size}px -${row * size}px` }} /> ) }
JavaScript gives you exact frame control, variable speeds, and works with any grid size (2x2, 3x3, 4x4). Perfect for pause, reverse, or trigger animations based on user actions.
Here are actual sprite sheets created with our AI generator. Different grid sizes create different animation styles - from simple 2x2 blinking to complex 3x3 movements!
Full Sprite Sheet
Animated Result
JavaScript: setCurrentFrame((prev) => (prev + 1) % 4)
Full Sprite Sheet
Animated Result
JavaScript: setCurrentFrame((prev) => (prev + 1) % 9)
Full Sprite Sheet
Animated Result
JavaScript: setCurrentFrame((prev) => (prev + 1) % 9)
Full Sprite Sheet
Animated Result
JavaScript: setCurrentFrame((prev) => (prev + 1) % 9)
Full Sprite Sheet
Animated Result
JavaScript: setCurrentFrame((prev) => (prev + 1) % 9)
function SpriteAnimation({ src, size = 64, speed = 150 }) { const [currentFrame, setCurrentFrame] = useState(0) useEffect(() => { const interval = setInterval(() => { setCurrentFrame((prev) => (prev + 1) % 9) // 9 frames }, speed) return () => clearInterval(interval) }, [speed]) // Calculate frame position (3x3 grid) const row = Math.floor(currentFrame / 3) const col = currentFrame % 3 return ( <div style={{ width: size, height: size, backgroundImage: `url(${src})`, backgroundSize: `${size * 3}px ${size * 3}px`, backgroundPosition: `-${col * size}px -${row * size}px`, }} /> ) }
This JavaScript approach gives you proper frame-by-frame animation with exact control over timing and frame progression!
Use our AI generator to make a sprite sheet with consistent characters. Choose your grid size based on how smooth you want the animation.
Upload the sprite sheet image to your website and add it to your HTML with a simple image tag or CSS background.
Copy our CSS code examples and adjust the timing and frame count to match your sprite sheet.
Refresh your website and watch your character come to life! Adjust the speed if needed.