Position Ninja — free CSS position game

Kai the ninja, Miso the cat, Bo the sleepy guard and Pip the messenger bird each have a spot to reach. Your CSS is the only way to move them: static, relative, absolute, fixed, sticky, z-index and anchors.

0/ 45
Mission 1
Live: 0 / 1 spots reached
easyMission 1 of 15

Static ignores you

Kai has to reach the rooftop, but the scroll of orders is being ignored.

Every element starts as position: static: it sits where normal flow puts it.

On a static element top, left, right and bottom do nothing. The browser silently skips them.

position: relative switches the offsets on. Kai then moves from the spot flow gave them.

Your task

Make the offsets work, so Kai lands on the rooftop.

  • Kai stands on the rooftop
  • uses position: relative
stage.htmlread only · sizes locked
<div class="ninja"></div>
moves.css

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

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