Building a game on the Popover API
The popover attribute turns any element into a popover. Left without a value, it defaults to auto, which gives the element light-dismiss behavior: clicking anywhere outside it closes it, and opening one auto popover closes any other non-nested popovers on the page. Setting popover="manual" instead produces an independent element that only opens and closes via its designated control.
Why the game starts inside <details>
A page can't load with a popover already open, and working around that without JavaScript isn't possible. The <details> element can be open by default, so the starting balloons live inside an open <details>; closing it pops every button balloon at once, leaving a single <summary> balloon behind.
<details open>
<summary>🎈</summary>
<button>🎈</button>
<button>🎈</button>
<button>🎈</button>
</details>
<dialog> would be more semantic, but two constraints rule it out: an open-on-load dialog can only be closed with JavaScript, and dialogs are modal, blocking the clicks on other balloons the game requires. The container is therefore <details open>, with popovers implemented as plain <div popover> elements.
Wiring balloons to popovers
Each popover gets a unique ID, and its triggering <button> references it through popovertarget. By default, that button both shows and hides its target, which makes the game too easy. Adding popovertargetaction set to show or hide restricts the button to that single action. Leaving the attribute off a button restores the toggle behavior.
Styling that hides the seams
The <summary> and <button> elements must look identical so players can't distinguish the two kinds of balloon. Most of the CSS is ordinary backgrounds, padding, sizing and borders, plus a handful of specific details:
list-style-type: noneon the<summary>removes the triangular open/closed marker, which would otherwise be a hint.- Safari needs
summary::-webkit-details-markerset todisplay: nonefor the same result. cursor: pointersignals that the balloons are clickable.user-select: none(plus the prefixed-webkit-user-selectfor Safari) keeps the emoji text from being selected, so balloons behave like objects.
.balloon {
background-color: transparent;
border: none;
cursor: pointer;
display: block;
font-size: 4em;
height: 1em;
list-style-type: none;
margin: 0;
padding: 0;
text-align: center;
-webkit-user-select: none; /* Safari fallback */
user-select: none;
width: 1em;
}
Some balloons appear to do nothing because the popovers they close aren't open, which can look like a broken click. A small scale applied in the :active state gives feedback at the moment of clicking.
.balloon:active {
scale: 0.7;
transition: 0.5s;
}
Placing balloons without JavaScript
Random positioning would need JavaScript, and custom-property "random" multipliers never produced a convincing scatter without overlaps or visible patterns. The working approach assigns rows and columns through classes based on physical insets — grid-like rather than actual CSS Grid or Multicolumns. The layout is an 8×8 grid with the first row and column left empty to keep balloons off the browser's left and top edges. As long as no balloon shares the same pair of classes, balloons never overlap.
/* Rows */
.r1 { --row: 1; }
.r2 { --row: 2; }
/* all the way up to .r7 */
/* Columns */
.c1 { --col: 1; }
.c2 { --col: 2; }
/* all the way up to .c7 */
.balloon {
/* This is how they're placed using the rows and columns */
top: calc(12.5vh * (var(--row) + 1) - 12.5vh);
left: calc(12.5vw * (var(--col) + 1) - 12.5vw);
}
Victory, failure and the timer
The game ends when the <details> with ID #root is no longer open. Hiding it with display: none via :not([open]), then using :has() on its parent, lets a sibling element with ID #congrats appear as a faux popover with the victory message.
#root:not([open]) {
display: none;
}
#game:has(#root:not([open])) #congrats {
display: flex;
}
Manual popovers stay open even when their ancestor <details> closes, so the message could appear too early. The :popover-open pseudo-class selects open popovers and, chained with :has(), acts as an AND condition: the congratulation is only shown when no popover remains open.
/* If #game does *not* have an open #root
* but has an element with an open popover
* (i.e. the game isn't over),
* then select the #congrats element...
*/
#game:has(#root:not([open])):has(:popover-open) #congrats {
/* ...and hide it */
display: none;
}
Failure is handled by an animation that runs for one minute and fades in a #fail message, since CSS lacks an if() conditional. A selector keeps #fail from displaying at the same time as #congrats.
#fail {
animation: fadein 0.5s forwards 60s;
display: flex;
opacity: 0;
z-index: -1;
}
@keyframes fadein {
0% {
opacity: 0;
z-index: -1;
}
100% {
opacity: 1;
z-index: 10;
}
}
#game:has(#root:not([open])) #fail {
display: none;
}
The timer itself is a full-width element (100vw) scaled horizontally over the same one-minute duration as the fade-in.
#timer {
width: 100vw;
height: 1em;
}
#bar {
animation: 60s timebar forwards;
background-color: #e60b0b;
width: 100vw;
height: 1em;
transform-origin: right;
}
@keyframes timebar {
0% {
scale: 1 1;
}
100% {
scale: 0 1;
}
}
A single point of failure makes the game too easy, so a second <details> element with ID #root2 is added; :has then checks that neither #root nor #root2 is open before #congrats is displayed.
#game:has(#root:not([open])):has(#root2:not([open])) #congrats {
display: flex;
}
The result is deliberately constrained: a JavaScript-free build trades robustness for the exercise, and it had no serious accessibility pass. The value is in pushing the API as far as it goes.



