Back to components
ComponentWidgetFree

2048 Game React component

A fully playable 2048, arrow-key and swipe controls, spring-animated tile merges, score and best-score tracking, and win/game-over overlays.

About the 2048 Game component

2048 Game is the sliding-number puzzle on a 4 by 4 board. Every move slides all tiles to one side, two equal tiles merge into their sum, and a new 2 (or sometimes a 4) appears in an empty cell. Reaching 2048 shows a win screen with a Keep Going option, and the game ends when no move is left.

Tiles move with the arrow keys or W, A, S and D once the board has focus, and with a swipe on touch screens. The score and the best score sit above the board, and the best score is saved in localStorage so it survives a reload. theme picks one of four looks (classic, neon, gold, night), each with its own title, and lightMode switches to a light background. It can also open as a popup from a pill button.

When to use it

Use it to keep people on a page a little longer: a 404 or maintenance page, a waiting screen, a fun corner of a portfolio or a campaign site.

For a quicker game that ends in a reward, use Spin to Win Wheel. For another classic puzzle, use Minesweeper Game.

Installation

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

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

Or copy the source by hand and install its dependencies:

Install
Copied!
npm install motion clsx tailwind-merge

More Widget components

Snake Game
Free
Tic Tac Toe Game
Free
Minesweeper Game
Free
Coin Flip Game
Free
Memory Match Game
Free
QR Code Widget
Free