Build a Tic-Tac-Toe Game

Paste one prompt into any AI chatbot and get a fully playable game in under 60 seconds. No coding knowledge needed.

AI Tutorials · · 3 min read · beginner · 2 min

What you’ll build

A fully working tic-tac-toe game that runs in your browser. Two players take turns clicking squares, it detects wins and draws, and has a restart button. All from a single prompt.

The prompt

Copy this entire block and paste it into any AI chatbot:

Create a complete, single-file HTML page with a tic-tac-toe game. Requirements:

- 3x3 grid of clickable squares, centered on the page
- Players alternate between X and O
- Display whose turn it is above the board
- Detect wins (3 in a row horizontally, vertically, or diagonally) and draws
- When someone wins, highlight the winning squares in green
- Show a "Play Again" button after the game ends
- Style it to look modern: use a dark background (#1a1a2e), white text, rounded squares with hover effects, and a clean sans-serif font
- Make it responsive so it works on mobile too
- All HTML, CSS, and JavaScript in a single file — no external dependencies

Output ONLY the complete HTML file, nothing else.

Where to paste it

Pick any of these — the prompt works on all of them:

  • ChatGPT — Free tier works. After it generates the code, click the preview/artifact to play it directly.
  • Claude — Free tier works. Claude shows an interactive artifact you can play immediately.
  • Gemini — Free tier works. Copy the code and open it in your browser (instructions below).

How to run it

If the AI shows an interactive preview (ChatGPT and Claude usually do): just click it and play.

If you get raw code:

  1. Select all the code and copy it
  2. Open any text editor (Notepad, TextEdit, etc.)
  3. Paste the code and save the file as tictactoe.html
  4. Double-click the file — it opens in your browser and you can play

What just happened

You just built a working game without writing a single line of code. The AI understood your requirements, wrote the HTML structure, styled it with CSS, and programmed the game logic in JavaScript — all in seconds.

This is what people mean when they say “AI can code.” You describe what you want, and it builds it.

Try tweaking it

Now that you have a working game, try asking the AI to modify it:

  • “Add a score counter that tracks wins for X and O”
  • “Make it so I can play against the computer”
  • “Change the colors to pink and purple”
  • “Add sound effects when you place a piece”

Each of these is just another prompt away.

Want to keep learning?

Explore our guided learning paths or try building something with AI right now.

Enjoyed this article?

Subscribe for more AI insights delivered to your inbox every week.

No spam. Unsubscribe anytime.