Back to components
ComponentWidgetFree

Snake Game React component

A canvas-rendered Snake game with three difficulty speeds, keyboard and swipe controls, a directional-eyes snake head, high-score tracking, and ready/game-over overlays.

About the Snake Game component

Snake Game is the classic arcade game drawn on a canvas. The snake moves across a square grid, grows by one segment for each piece of food it eats, and the game ends when it hits a wall or its own tail. Each piece of food is a point, and the high score is kept in localStorage.

It is controlled with the arrow keys, W, A, S and D, or a swipe, and pressing an arrow key or Space starts a new game. defaultDifficulty sets the speed (easy, medium or hard, one step every 160, 110 or 70ms) and gridSize the number of cells per side, from 8 to 24 (15 by default). theme picks classic, violet or retro colors. The game pauses its loop while it is scrolled out of view.

When to use it

Use it on a 404 page, a launch countdown, a developer portfolio or any page where a quick game fits the tone, inline or as a popup opened from a button.

For a calmer puzzle without a time pressure, use 2048 Game or Minesweeper Game.

Installation

Add the Snake Game component to your project with the shadcn CLI. It lands in components/snake-game.tsx as plain React + Tailwind CSS source you own and can edit.

Install
Copied!
npx shadcn@latest add @reactframe/snake-game

Or copy the source by hand and install its dependencies:

Install
Copied!
npm install clsx tailwind-merge

More Widget components

Minesweeper Game
Free
2048 Game
Free
Memory Match Game
Free
Tic Tac Toe Game
Free
Pong Game
Free
Coin Flip Game
Free