About Position Ninja
Position Ninja is a free CSS position game: every character has a spot to reach, and your CSS is the only way to move them. The browser’s own layout engine checks each spot, from position: relative to sticky, fixed traps and anchor positioning.
How to play Position Ninja
Each mission has characters and target spots. The only way to move a character is to write CSS for it, and the browser's own layout engine checks whether it landed on the spot. Missions move from relative and absolute positioning to sticky, fixed, stacking contexts and anchor positioning.
The five position values
static is the default: the element follows normal flow and top, left, right and bottom are ignored. relative keeps the element's space in the flow but shifts it visually from where it would have been. absolute removes the element from the flow and positions it against its containing block, which is the nearest ancestor with a position other than static.
fixed positions the element against the viewport, so it stays put when the page scrolls. sticky behaves like relative until a scroll threshold such as top: 0 is reached, and then sticks inside its parent.
.card { position: relative; } /* containing block */
.badge { position: absolute; top: 8px; right: 8px; }
.modal { position: fixed; inset: 0; } /* covers the viewport */
.header { position: sticky; top: 0; }
/* Center an absolute element */
.center { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); }
z-index and stacking contexts
A higher z-index only wins against elements in the same stacking context. Properties like opacity below 1, transform, filter and position with a z-index create a new stacking context, and nothing inside it can rise above an element outside it, no matter how high its z-index.
This is why a dropdown with z-index: 9999 can still hide behind a header: its parent created a stacking context with a lower layer.
Traps and interview questions
position: sticky silently fails if any ancestor has overflow: hidden, auto or scroll, because the element sticks to that scroll container instead of the page. position: fixed stops being relative to the viewport if an ancestor has a transform. Both are favourite interview debugging questions.
Also expect: what is the difference between absolute and fixed, and how do you position a tooltip next to a button? Modern CSS answers the second with anchor positioning, which Position Ninja covers in its final missions.
What you practice
- static vs relative
- absolute & containing block
- inset & centering
- z-index & stacking contexts
- sticky & fixed
- anchor positioning
FAQ
- What is Position Ninja?
- Position Ninja is a free browser game on Playhire for the CSS position property. You write real CSS to move a ninja, a cat, a guard and a bird onto target spots across 15 missions, from easy to pro.
- Which CSS position topics does it cover?
- static, relative, absolute, the containing block, right/bottom and inset, centering with translate, z-index and stacking contexts, sticky (top and bottom), fixed, the overflow and transform traps that break sticky and fixed, and CSS anchor positioning.
- Are Playhire CSS games free, and do I need to install anything?
- They are free and run in the browser, with nothing to install and no signup needed to start. Sign in only if you want XP, leaderboard rank and certificates.
- Is this a Flexbox Froggy alternative?
- Playhire’s Flexbox games teach the same CSS Flexbox skills (justify-content, align-items, flex-direction, gap, order, flex-grow) but with different themes: escape rooms, shooters, blueprints and drone docking — plus Grid, selectors and HTML labs on the CSS Master path.
More CSS games