A modern, interactive Snake game built with vanilla HTML, CSS, and JavaScript.
Play it directly in your browser — no dependencies, no build tools.
Control a snake on a grid-based board. Eat the red food pellets to grow longer and increase your score. Avoid hitting the walls or your own tail — one collision and it's game over.
| Control | Action |
|---|---|
↑ ↓ ← → or W A S D |
Change direction |
Space |
Pause / Resume |
| Swipe (mobile) | Change direction |
| Tap (mobile) | Unpause / Restart |
- Smooth rendering — interpolated movement between game ticks for fluid visuals
- Adjustable FPS — choose 30, 60, 120, unlimited, or a custom frame rate
- Visual effects — glow/shadows, food pulse animation, grid lines (all toggleable)
- High score — persisted in localStorage, survives page reloads
- Game timer — tracks how long you've survived
- Pause overlay — pause anytime with Space or the pause button
- Mobile friendly — responsive layout with touch/swipe support
- Settings panel — gear icon opens a modal with all configuration options
A modern web browser (Chrome, Firefox, Safari, Edge).
- Clone or download this repository
- Open
index.htmlin your browser
That's it. No npm install, no dev server, no build step.
# Or serve with any static server:
npx serve .JS/
├── index.html Entry point & HTML structure
├── style.css All styling (dark theme, responsive, animations)
├── server.js Game logic & rendering engine
└── README.md This file
| File | Purpose |
|---|---|
index.html |
Canvas, settings panel, info bar (score, timer, high score), overlays |
style.css |
CSS custom properties, flexbox/grid layout, backdrop blur, toggle switches, mobile breakpoints |
server.js |
Snake movement, collision detection, food generation, rendering (canvas API), FPS throttle, touch/keyboard input, localStorage persistence |
Click the ⚙ gear icon to open the settings panel:
| Setting | Description |
|---|---|
| Target FPS | Limit render FPS to 30, 60, 120, unlimited, or custom |
| Glow / shadows | Toggle shadow effects on snake head and food |
| Food pulse animation | Toggle breathing animation on food |
| Grid lines | Show/hide the subtle background grid |
| Show FPS counter | Show/hide the FPS display in the info bar |
All settings are persisted in localStorage.
MIT — feel free to use, modify, and share.