DEV Community

Cover image for CSS games are fun!
Alvaro Montoro
Alvaro Montoro Subscriber

Posted on • Edited on • Originally published at alvaromontoro.com

15 6

CSS games are fun!

CSS games (small games developed exclusively with CSS and HTML, without any JavaScript) are often dismissed by developers as a waste of time. And they may have a point if you consider performance and maintainability.

But...

If you look at them from a different point of view, developing games using CSS makes for some cool challenges, and they can be a great learning experience. You need to:

  1. Use more complex selectors.
  2. Deal with specificity conflicts.
  3. Practice combinators and pseudo-classes.

Not to mention that the CSS-only restriction puts the focus on the analysis and design and forces the developer to stop and think before jumping into coding.

With that in mind, and stuck at home with a cold on Saturday, I decided to give it a try and develop a tic-tac-toe game using only CSS and HTML.

There are many examples of CSS tic-tac-toes online like this one from Žiga Miklič or this other one from Jhey. And they actually look better than mine... So I decided to take mine one step further.

By adding some "artificial intelligence" (using this term quite loosely here), I was able to make it so the machine would actually play with some logic and a "winning mentality."

Here is a demo. I know it may be a bit silly, but it is something that I feel proud of.

What is your experience with CSS games? Have you developed one before? Please share, I'd love to see them.

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

Top comments (7)

Collapse
 
karataev profile image
Eugene Karataev

It's mindblowing that it's possible to add such level of interactivity with just pure CSS nowdays.

P.S. It's hard to play the game here on dev.to, because the the browser's viewport is scrolled to the page's top on every user interaction 🤣

Collapse
 
alvaromontoro profile image
Alvaro Montoro

I realized about that, that's why I added the link to the CodePen demo, but it is not too obvious within the post itself :-/

Collapse
 
patsyjmoore1 profile image
Patsy J. Moore

It will definitely add to our knowledge.

Collapse
 
lmolivera profile image
Lucas Olivera

I have never heard of this before. It amazes me how complex CSS can be!

Collapse
 
steffenpedersen profile image
Steffen Pedersen

This is so awesome 😎 The "artificial intelligence" is not the brightest, but it is amazing, that it is even possible 😃

Collapse
 
kleene1 profile image
kleene1

Wow

Collapse
 
ezra_ezra_69aeb3bc575bba8 profile image
Ezra Ezra

This is such a creative way to push the limits of CSS! I completely agree that developing CSS-only games can be a great learning experience, especially when it comes to mastering selectors, combinators, and pseudo-classes.

I recently came across a resource that might interest anyone diving into such creative experiments – Todocoinmaster.com. It’s a platform that discusses various innovative projects, including unique approaches to web development. Check it out!

Looking forward to seeing more of your CSS experiments. Keep up the great work!

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay