Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

You can build a small balloon-popping browser game with HTML and CSS by treating each emoji balloon as a button-controlled popover. John Rhea’s CSS-Tricks tutorial, “Pop(over) the Balloons”, shows how native popover controls, :has(), :popover-open, and CSS animation can create game interactions without JavaScript.

How the popover game works

The balloons are emoji in the page, not physical balloons. Each balloon or group is represented by HTML, and the Popover API supplies the open-and-close behavior. The game is a demonstration of how far HTML and CSS can go for a small interaction, rather than a tested or production-ready game.

Rhea’s July 25, 2024 tutorial begins with the idea that “I’ve always been fascinated with how much we can do with just HTML and CSS.” The linked CodePen demo presents the player with a two-minute challenge and notes that some balloons create more balloons while others pop other balloons. Those are instructions and behaviors in the example, not independently measured game results.

Why use popovers for the balloons?

An element with the popover attribute can be controlled by a button that points to its ID through popovertarget. The tutorial uses manual popovers for game pieces, so they open or close through their intended controls instead of dismissing when the player clicks elsewhere.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Sale
HTML and CSS: Design and Build Websites
  • HTML CSS Design and Build Web Sites
  • Comes with secure packaging
  • It can be a gift option

The distinction matters: an auto popover can be light-dismissed and interacts with other auto popovers, while a manual popover requires an explicit control to close it. A control can specify popovertargetaction="show" or "hide" to perform one action rather than toggle. If the action is omitted, the control uses the default toggle behavior.

Why the game starts with <details open>

The initial game state needs to show balloons as soon as the page loads. The tutorial wraps its starting content in an open <details> element, with a balloon in <summary> and additional button balloons inside. This works without JavaScript because <details open> can be open on page load; popovers in this JavaScript-free construction cannot be loaded already open.

Buttons target popover elements by ID. The markup therefore connects visible game controls to the relevant balloon group, while CSS styles summaries and buttons to look and behave like clickable game pieces. Rhea’s example also removes the disclosure marker, prevents text selection, and includes a Safari-specific marker selector and a prefixed user-select property. Those are details of the 2024 example, not current browser-compatibility guidance.

How CSS provides layout and game state

Positioning the balloons

The tutorial assigns classes for rows and columns, then uses viewport units to position the balloons. The result is a grid-like distribution rather than genuinely random placement, so it should be understood as a composed layout, not a random game board.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Showing a win state

Selectors including :has() and :popover-open let the stylesheet respond to the state of the popovers and closed root <details> elements. In the tutorial, those conditions determine when the success message is revealed.

Timing a loss state

A CSS animation drives the progress bar and delays the failure message. This provides the two-minute countdown presented in the demo without a JavaScript timer. The timer is a game setting, not a published statistic about player performance.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

What to consider before adapting the example

  • Accessibility: The tutorial says the example did not receive a good-faith accessibility pass. Do not treat it as an accessibility model; assess keyboard operation, screen-reader communication, motion, contrast, and timing needs for your own implementation.
  • Browser support: The article was published in 2024, and current support for every API and CSS feature used is not established by that tutorial. Check current browser documentation for the browsers and versions your project targets before relying on popovers or selectors such as :has().
  • Interaction complexity: The demo is a compact proof of concept. If you need richer game state, accessible timing controls, reliable randomness, scoring, or compatibility fallbacks, evaluate whether HTML and CSS alone are sufficient for your requirements.

For the full walkthrough and its implementation, see John Rhea’s CSS-Tricks article and the final CodePen.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.