2048 Game Using HTML, CSS and JavaScript with Source Code


Welcome to the 2048 Game, a captivating sliding block puzzle that has taken the gaming world by storm. This web-based implementation brings the addictive gameplay experience right to your browser using modern web technologies. Players are tasked with combining numbered tiles on a 4x4 grid to create a tile with the value of 2048. Each move slides the tiles in one of four directions, merging tiles with the same number to form larger values. The game's sleek design and smooth animations make it both visually appealing and highly engaging, encouraging players to think strategically about their moves to maximize their score.

This project leverages HTML, CSS, and JavaScript to deliver a seamless and interactive gaming experience. HTML provides the structural foundation of the game, creating the grid and interface elements. CSS is used to style the game, ensuring it is responsive and visually consistent across different devices. JavaScript handles the core game logic, including tile generation, movement, merging, and score tracking. With support for both keyboard and touch controls, the 2048 Game offers an accessible and enjoyable experience for players on both desktop and mobile devices. Dive into the challenge and see if you can reach the coveted 2048 tile!

You may also check this simple HTML, CSS and JavaScript projects:


  • Dynamic Grid System: The game features a 4x4 grid where tiles with numbers 2, 4, 8, 16, and beyond can be merged.
  • Responsive Design: The game's layout is responsive, providing an optimal playing experience across different devices and screen sizes.
  • Touch and Keyboard Controls: The game supports both touch controls for mobile devices and keyboard controls for desktop users.
  • Score Tracking: The game keeps track of the player's score, displaying it prominently above the grid.
  • Game Over Detection: The game automatically detects when there are no possible moves left, displaying a "Game Over" message and the final score.
  • Restart Capability: Players can restart the game at any time with the click of a button.

Technologies Used:

  • HTML5: Provides the structure of the game, including the grid and game controls.
  • CSS3: Styles the game with a modern and clean look, using Flexbox for layout and CSS classes for dynamic styling of tiles.
  • JavaScript: Implements the game logic, including tile generation, merging, movement, and score calculation. Event listeners are used to handle user inputs for both keyboard and touch controls.

How to Use:

  1. Start the Game: Click the "Start Game" button to initialize the game. The grid will populate with two randomly placed tiles, each with a value of 2 or 4.
  2. Move Tiles: Use the arrow keys (left, right, up, down) on your keyboard to slide the tiles in the respective direction. On touch devices, swipe in the desired direction to move the tiles.
  3. Combine Tiles: When two tiles with the same number collide, they merge into a single tile with their combined value. For example, two tiles with a value of 2 will merge into a tile with a value of 4.
  4. Score Points: Every time tiles combine, points equal to the value of the new tile are added to your score. The current score is displayed at the top of the game container.
  5. Game Over: The game ends when there are no more possible moves. A "Game Over" message will appear, showing your final score. You can restart the game by clicking the "Restart Game" button.
  6. Continue Playing: Aim to combine tiles and reach the 2048 tile, or even higher! The game can be restarted at any point if you wish to try again

Sample Screenshots of the Project:

Landing Page

In Game


How to Run?

  • Download the provided source code zip file.
  • Extract the downloaded zip file.
  • Open the html file and you are now ready to go!

Video Demonstration for Installation/Setup:


In conclusion, the 2048 Game project showcases the power and versatility of HTML, CSS, and JavaScript in creating an engaging and interactive web-based application. This implementation not only captures the essence of the original game but also enhances it with smooth animations and responsive design, making it accessible on various devices. By combining these technologies, the project delivers a seamless and enjoyable user experience, demonstrating how modern web development techniques can bring classic puzzle games to life in the digital age. Whether you're a seasoned gamer or new to 2048, this game offers a delightful and challenging experience that keeps you coming back for more.

That's it! I hope this "Gender Predictor By Name Using HTML, CSS and JavaScript" will assist you on your programming journey, providing value to your current and upcoming projects.

For additional tutorials and free source codes, explore our website.

Enjoy Coding :>>

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.

Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.


1. Re-scan downloaded files using your personal virus checker before using it.
2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.

Add new comment