Skip to main content

Snake Game

Steer the snake around a 20x20 grid; eat food, avoid walls and your own tail.

Written by Golam Rabbani, Founder & Lead Engineer

Score: 0Direction: right

Use arrow keys, WASD, on-screen buttons, or swipe.

How to use this snake game

  1. Use arrow keys or WASD to steer the snake; on touch screens, swipe in the direction you want to go.
  2. Eat the red dot to grow the snake by one segment and add a point to your score.
  3. Avoid colliding with the walls or with your own tail — either ends the game.
  4. Use Pause to stop the tick, and Restart at any time to wipe the board and start over.

About this snake game

Snake is the classic arcade game where a constantly-moving snake hunts food on a fixed 20×20 grid. Every tick — roughly 110 milliseconds — the snake's head advances one cell in the current direction. When the head lands on the red food dot, the tail grows by one segment and a new dot spawns at a random empty cell. Steer into a wall or into your own body and the game ends immediately.

Under the hood the game loop uses requestAnimationFrame and tracks elapsed wall-clock time to decide when to advance the snake. This separates frame rate from game speed: the snake moves at the same pace whether your display runs at 60 Hz, 120 Hz, or 240 Hz. Browser tab throttling is also handled gracefully — accumulated time is capped so the snake does not lurch forward in a burst when you tab back in.

To illustrate how the scoring and growth work: you start with a 3-segment snake and a score of 0. After eating 10 food dots your snake is 13 segments long and your score reads 10 — one point per dot, no multipliers. The tick rate never changes, so every additional segment is the only source of escalating difficulty. Once your snake stretches across roughly a third of the board, threading it through the remaining open cells becomes a genuine spatial planning challenge. A practical strategy is to hug the outer walls early so the centre stays clear as an escape corridor later in the game.

FAQ

Why can't I reverse direction directly?
Pressing the opposite arrow would instantly drive the snake into its own neck — an automatic loss. The game ignores 180-degree turns so you always need at least one perpendicular move to flip direction.
How fast does the snake move?
One cell every ~110 milliseconds, about 9 cells per second. The tick rate stays constant; the only thing that changes is the size of the snake you have to navigate.
Does the snake speed up as I score?
No, the speed is fixed in this version. Difficulty comes from the growing tail, not from a creeping tick rate, which keeps reaction-time skill and planning skill on the same playing field.
Can I play on mobile?
Yes. Swipe across the board to turn the snake. The grid scales to the viewport and the on-screen arrow buttons give you a fallback if swipes aren't landing cleanly.
What happens at the edge of the board?
The walls are solid — running into them ends the game. Some Snake variants wrap around; this one keeps the classic rules.
Is the high score saved?
No, scores are kept only in memory for the session. Refreshing the page resets everything to zero.