Skip to content

HTML file

An HTML file is a web page saved in one file ending in .html. You open it with a double-click in the browser, and a whole game can run inside it.

Filip Kostecki

Published

A game from an AI chat is usually 1 HTML file. You don’t install anything: you save the code from the chat as a file, double-click it and play. Later you can upload the same file to itch.io or to your own address.

How does it work?

  1. HTML tells the browser what’s on the page: text, buttons, the game area.
  2. The <script> tag in the same file holds the JavaScript code, which is the logic of the game: movement, the score, the end of a round.
  3. The game is drawn in a <canvas> element, which is used for game graphics and animation, among other things.
  4. The file can load a game library, for example Phaser, from the internet with one <script> tag.

Example from practice

The first version of my game SlipZone is 421 lines of code in one file, slipzone-v1.html. I saved each later version in a new file (v3, v4, v5), so after failed fixes I had something to go back to. When I added graphics from separate PNG files, a double-click showed dark squares instead of the ship: Chrome blocks files next to a page opened from the disk. The game with graphics worked only after I uploaded it to itch.io or to Netlify Drop. I describe the whole route in the article on how to make a browser game with AI.

What to watch out for

  • A page from the disk. A file opened with a double-click has a file:// address, and the browser then blocks some requests for other files. Graphics and sounds in separate files may not load.
  • A library from the internet. A game that loads its library from the web won’t start without the internet, and the game portal Poki doesn’t allow such requests.
  • A code fragment. A piece of code without the start and the end of the file won’t work. Ask the chat for the full file.
  • The file name. In a ZIP on itch.io and in a folder on Netlify, the main game file is called index.html.

I describe how to get a working HTML file out of the chat, and how to add to the game without breaking what already works, in the e-book “Make a Game with AI in a Weekend”.

See the e-book

Questions and answers

How do I save code from the chat as an HTML file?

Copy all the code and save it in a text editor as a file ending in .html, for example my-game-v1.html. Check that the code starts with <!DOCTYPE html> and ends with </html>.

Will an HTML game file work on a phone?

Yes, if the game has touch controls. Open it on the phone from an address on the internet, for example from a draft on itch.io or from Netlify Drop.

See also

Articles that use this term

Filip Kostecki

Founder of FKDRIVE and software developer. Builds and maintains web systems and automation.

Let us talk about your project.

Thirty minutes online about one or two processes that eat the most time. If you would rather write, the contact form is just as good a route.

Book 30 minutes

COOKIES

Without cookies we are working in the dark

We have no way of telling which parts of this site help somebody and which ought to go. Consent switches on visit statistics, session recordings with form content masked automatically, and measurement of how our advertising performs. We do not trade in your data and we do not sell it to anyone.

You can change this at any time with the “Cookie settings” link in the footer. What exactly we collect →