Open links in new tab
  1. Designed by

    First appeared

    35+ Free JavaScript Games (Code+ Demo)

    Learn how to create various fun and simple Javascript games with code and demo examples. Explore puzzles, card games, arcade games, and more with HTML, CSS…

    Foolish Developer
    HTML Game Example - W3Schools

    Learn how to make games, using nothing but HTML and JavaScript. Push the buttons to move the red square: With our online editor, you can edit the code, and click on a button to view the result.

    W3School
  1. Creating games with JavaScript is a great way to learn and practice programming. Below is an example of a simple Snake Game implemented in JavaScript.

    Example: Snake Game

    // Initialize the canvas and context
    const canvas = document.getElementById("gameCanvas");
    const ctx = canvas.getContext("2d");

    // Set up the game variables
    let snake = [{ x: 200, y: 200 }];
    let direction = "RIGHT";
    let food = { x: Math.floor(Math.random() * 20) * 20, y: Math.floor(Math.random() * 20) * 20 };
    let score = 0;

    // Function to draw the snake
    function drawSnake() {
    ctx.clearRect(0, 0, canvas.width, canvas.height);
    snake.forEach(part => {
    ctx.fillStyle = "green";
    ctx.fillRect(part.x, part.y, 20, 20);
    });
    }

    // Function to move the snake
    function moveSnake() {
    const head = { x: snake[0].x, y: snake[0].y };
    if (direction === "RIGHT") head.x += 20;
    if (direction === "LEFT") head.x -= 20;
    if (direction === "UP") head.y -= 20;
    if (direction === "DOWN") head.y += 20;

    snake.unshift(head);
    if (head.x === food.x && head.y === food.y) {
    score += 10;
    food = { x: Math.floor(Math.random() * 20) * 20, y: Math.floor(Math.random() * 20) * 20 };
    } else {
    snake.pop();
    }
    }

    // Function to draw the food
    function drawFood() {
    ctx.fillStyle = "red";
    ctx.fillRect(food.x, food.y, 20, 20);
    }

    // Function to update the game state
    function updateGame() {
    moveSnake();
    drawSnake();
    drawFood();
    }

    // Event listener for key presses
    document.addEventListener("keydown", event => {
    if (event.key === "ArrowRight" && direction !== "LEFT") direction = "RIGHT";
    if (event.key === "ArrowLeft" && direction !== "RIGHT") direction = "LEFT";
    if (event.key === "ArrowUp" && direction !== "DOWN") direction = "UP";
    if (event.key === "ArrowDown" && direction !== "UP") direction = "DOWN";
    });

    // Game loop
    setInterval(updateGame, 100);
    Copied!
    Feedback
  2. 35+ Free JavaScript Games (Code+ Demo)

    Jan 4, 2024 · Learn how to create various fun and simple Javascript games with code and demo examples. Explore puzzles, card games, arcade games, and more with HTML, CSS, and Phaser …

  3. HTML Game Example - W3Schools

    Learn how to make games, using nothing but HTML and JavaScript. Push the buttons to move the red square: With our online editor, you can edit the code, and click on a button to view the result.

  4. 36 JavaScript Games | FreeFrontend

    5 days ago · A collection of fun and interactive JavaScript games. From classic recreations to unique, custom-made mini-games, all built with pure HTML, CSS, and JavaScript.

  5. javascript-games · GitHub Topics · GitHub

    Here are 102 public repositories matching this topic... Build 100+ Projects In 100 Days Using HTML, CSS and JAVASCRIPT. A curated list of awesome JavaScript Games 🎮. Provides a well …

  6. 15+ Games Using JavaScript [Demo + Free Code]

    Mar 23, 2024 · Whether you are a beginner or a professional web developer these JavaScript game source codes will always help you. There are many JavaScript games like Simple Games, …

  7. People also ask
  8. Javascript Mini Games

    A collection of fun mini games built with JavaScript, complete with code examples and documentation.

  9. 2D breakout game using pure JavaScript - MDN

    Aug 2, 2025 · In this step-by-step tutorial we create an MDN Breakout game written entirely in pure JavaScript and rendered on HTML <canvas>. Every step has editable, live samples available to …

  10. JavaScript Snake game tutorial: Build a simple, interactive game

    May 5, 2025 · This tutorial will guide you in building a simple, interactive Snake game using HTML, CSS, and JavaScript. You’ll have a fun game and a better grasp of core web development …

  11. How to Build a Simple Game with JavaScript - itch.io

    Jun 17, 2025 · JavaScript can do more than build websites—it can also power fun games! In this guide, you’ll learn how to build a simple browser-based game using plain JavaScript, HTML, and …