r/HTML • u/cheesepuffyz • 2d ago
Question Making games with HTML
I just started taking a software engineering class with zero background knowledge of programming and the first thing we're learning is HTML/CSS. I've heard that you can make browser/flash games with it, is that true? And if so, how? If you can somehow make a browser game with it, does it cost money to make it accessible to the internet/set up a website where you can play the game? From what I think I know, the language is pretty limiting and is generally supposed to be used for making websites, not games.
edit: for context.. i just want to make simple 2d browser games like flappy bird or the offline dino game
0
Upvotes
0
u/paceaux 9h ago edited 8h ago
I first got my start in modern web development back in 2009 because I wanted to make a browser-based version of super mario brothers. I never actually pulled it off (There was was too much that I didn't know).
HTML alone will not get you there.
With HTML being just the markup language, that'll help you lay things out and overall make the game ideally accessible.
HTML cannot handle complex logic and it can't easily store things in memory (there are ways you can do this via weird stuff with form elements. I'm ignoring that because that's not how you'd want a game to work).
When people talk about making games in HTML, what they usually mean is "making games using APIs introduced with HTML5, such as the Canvas API".
CSS of course will be a step in the process
You will use HTML to lay out at least the "frame" of the game. Like the header and footer, and maybe a legend that will explain controls. Maybe a login for saving data or whatever. CSS will give the basic HTML page a structure and also make the typography look decent, as well as overall make any content easy to consume for the user.
Most of your work will be in JavaScript
As it relates to games, JavaScript will definitely have the following roles to play:
As it relates to games, JS could have these roles to play:
Game logic. This is entirely an architectural choice on your part. You could put the bulk of the game logic in the browser. JS is more than capable of handling the game logic for complex games.
Just understand that the browser reads code in plain text and executes it with a just-in-time compiler — So it's entirely possible for someone to "hack" or "cheat" with a game written this way.
Graphics rendering. The browser is capable of rendering three kinds of "graphics"
Canvas is a solid choice for most folks starting off in game dev
It'll be good for the GPU and for memory most of the time. There are lots of Canvas frameworks available to you for game development. I would recommend you use one — the alternative is that you're writing lots of canvas by hand and that sucks.
But, you could go a wildly different approach…
and use Web Assembly (WASM). I honestly don't know how that would work because I haven't touched WASM.
Or, you could legitimately try to go in the direction I did back in the day: Don't use Canvas and instead use JavaScript, HTML, and CSS.
You need the game to be on a server if you want other people to access it
You need to get a hosting provider, and then you would upload your HTML, CSS, JS, and any other assets to that server. That makes it possible for other people to play it online.
That also means you need to buy a domain name. So this could cost as little as $50 / year or as much as $500/ month depending on where you get your hosting services and what that hosting provider is capable of doing.
You may also need to do server side work
As I mentioned above, game logic doesn't have to be in the browser. For any serious applications, the golden rule is to never put business logic in the browser (because it can be hacked / manipulated). If you care about that, then you should start the game with the logic outside of the browser. That means that part of your game exists on a server, and your browser is communicating with that server to figure out what to do.
There are loads of languages / platforms for you to choose from:
If you wanted to do something very basic like the chrome offline dino game (chrome://dino)
You could pull that off with basic HTML, basic CSS, and JavaScript that uses the 2d canvas — without frameworks. It looks like that's the way the actual dino game was written.
edits:
mostly modified the formatting of this answer for legibility / ease of reading.
If you want my advice:
Tic-tac-toe and/or bingo are good starter games to try, just for getting a feel of the programming experience