A fast, responsive Snake game implementation using pure vanilla JavaScript, HTML5, and CSS3. No frameworks, no dependencies - just classic arcade gaming fun in your browser! Challenge yourself to beat your high score while the snake grows longer with each apple eaten.
- ๐ฎ Classic Gameplay - Smooth snake movement with collision detection
- ๐ High Score Tracking - Persistent high scores saved in local storage
- โฑ๏ธ Timer - Track how long you've been playing
- ๐ Theme Switcher - Toggle between light and dark modes
- ๐๏ธ Speed Control - Dynamically adjust game speed during gameplay
- ๐ฑ Responsive Design - Works on desktop and mobile devices
- โก Vanilla JavaScript - No frameworks or external dependencies
- ๐พ Local Storage - Saves high score and theme preferences
- ๐ฏ Wrapping Borders - Snake wraps around screen edges
- ๐ Visual Snake Head - Distinct head styling for better visibility
| Key | Action |
|---|---|
| Arrow Up โฌ๏ธ | Move Up |
| Arrow Down โฌ๏ธ | Move Down |
| Arrow Left โฌ ๏ธ | Move Left |
| Arrow Right โก๏ธ | Move Right |
| Start/Pause Button | Start or pause the game |
| Restart Button | Restart the game |
| Speed Up Button | Increase game speed |
| Speed Down Button | Decrease game speed |
| Theme Button | Toggle light/dark mode |
- A modern web browser (Chrome, Firefox, Safari, Edge)
- No additional software required!
-
Clone the repository
git clone https://github.com/PiyushRepos/snake-game.git
-
Navigate to the project directory
cd snake-game -
Open in browser
-
Simply open
index.htmlin your web browser -
Or use a local server:
# Using Python 3 python -m http.server 8000 # Using Node.js npx serve
-
Then visit
http://localhost:8000
-
snake-game/
โ
โโโ assets/
โ โโโ snake-game-banner.svg # README banner image
โ โโโ default-og.png # Open Graph image
โ โโโ light-mode.png # Screenshot (if available)
โโโ index.html # Main HTML file
โโโ script.js # Game logic and functionality
โโโ styles.css # Styling and themes
โโโ README.md # Project documentation
- Start the Game - Click the "Start" button or press it to begin
- Control the Snake - Use arrow keys to change direction
- Eat Apples ๐ - Guide the snake to the red apple to grow longer
- Avoid Collision - Don't run into yourself!
- Beat Your High Score - Try to grow the longest snake possible
- The snake moves continuously in the current direction
- You cannot reverse direction (e.g., if moving right, can't go directly left)
- Each apple eaten increases your score by 1
- The snake grows longer with each apple consumed
- Game ends when the snake collides with itself
- The snake wraps around screen edges (goes through walls)
- HTML5 - Structure and semantics
- CSS3 - Styling, animations, and responsive design
- CSS Grid for game board layout
- CSS Custom Properties for theming
- CSS Animations for visual effects
- Vanilla JavaScript - Game logic and interactivity
- DOM manipulation
- Event handling
- Local Storage API
- Game loop with setInterval
You can now adjust the game speed in real-time using the Speed Up and Speed Down buttons during gameplay!
Alternatively, edit the initial SPEED variable in script.js:
let SPEED = 150; // milliseconds (lower = faster)Speed Range: 50ms (fastest) to 500ms (slowest)
Modify the --block-size CSS variable in styles.css:
:root {
--block-size: 30px; /* Change this value */
}Extend the CSS variables in the .dark class or create new theme classes in styles.css.
- Automatically saves your highest score to browser local storage
- Persists across browser sessions
- Updates in real-time when you beat your record
- Adjust game speed on-the-fly with Speed Up/Down buttons
- Speed range from 50ms (blazing fast) to 500ms (beginner-friendly)
- Changes take effect immediately during active gameplay
- Great for progressive difficulty or accessibility needs
- Light mode (default) with bright, clean aesthetics
- Dark mode for comfortable night-time gaming
- Theme preference saved in local storage
- Smooth transitions between themes
- Adapts to different screen sizes
- Touch-friendly on mobile devices
- Flexible grid layout adjusts to available space
- Visual distinction between snake head and body segments
- โ Chrome (latest)
- โ Firefox (latest)
- โ Safari (latest)
- โ Edge (latest)
- โ Opera (latest)
Contributions are welcome! Here's how you can help:
- Fork the repository
- Create a feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is open source and available under the MIT License.
Piyush Kumar
- GitHub: @PiyushRepos
- Repository: snake-game
- Inspired by the classic Nokia Snake game
- Built as a learning project for vanilla JavaScript game development
- Thanks to the open-source community for inspiration
Enjoy the game! ๐ฎ๐
If you like this project, please give it a โญ

