1. Docs
  2. Guides

Animations and effects

Build a 10-second tap game from the smallest app: three screens in one, a countdown, a tap counter, a best score that's remembered, and confetti when time's up.

8 steps · ends in a tap game with a countdown and confetti

This tag has more than one name. Every spelling is the same tag, so write whichever feels natural. Pick one and every example on this page uses it.

Motion in HAM runs on the phone. You don't send frames; you name the effect, and the device plays it at full frame rate: a punch when something is tapped, a pop when it appears, a countdown that ticks, a burst of confetti. Each is a style token, a tag or one action, and each turns itself off when the phone asks for reduced motion.

This guide builds Tap rush: tap the circle as many times as you can in 10 seconds.

Step 1 of 8

Start with the smallest app

Every HAM document starts with <app>. A <screen> is one page of the app, and <main> holds what's on it: for now, one line of <text>.

app.ham · step 1
<app>    <screen>        <main>            <text>Hello</text>        </main>    </screen></app>
Step 1 on a phone: Start with the smallest app Step 1 on a phone, dark: Start with the smallest app
Step 1, drawn by the engine from the snippet beside it.

Step 2 of 8

Add a title bar and a color

<app-bar> puts the game's name across the top, and <config primary_color="red"> gives every control a red. Use a named color like red, teal or amber.

app.ham · step 22 new lines
<app>    <config primary_color="red"/>    <screen>        <app-bar title="Tap rush"/>        <main>            <text>Hello</text>        </main>    </screen></app>
Step 2 on a phone: Add a title bar and a color Step 2 on a phone, dark: Add a title bar and a color
Step 2, drawn by the engine from the snippet beside it.

Step 3 of 8

Lay out the start screen

A <stack> holds the game. It draws its children in layers, and the second layer comes later. In it, a <column> with the question and a Start button.

app.ham · step 36 new lines
<app>    <config primary_color="red"/>    <screen>        <app-bar title="Tap rush"/>        <main>            <stack style="w-full">                <column>                    <text>How many taps in 10 seconds?</text>                    <button>Start</button>                </column>            </stack>        </main>    </screen></app>
Step 3 on a phone: Lay out the start screen Step 3 on a phone, dark: Lay out the start screen
Step 3, drawn by the engine from the snippet beside it.

Step 4 of 8

Three screens in one

The game has three states, so <globals state="ready"/> declares $state for the whole app. <@if>, <@elseif> and <@else> build only the branch whose test is true:

  • ready: the question and Start, which sets $state = 'playing';
  • playing: a <countdown> from 10, whose on-done sets $state = 'done' when it reaches zero;
  • done: Time's up, and Again, back to ready.

Switching branches builds the new one fresh, so the countdown starts from 10 every time.

app.ham · step 412 new lines
<app>    <config primary_color="red"/>    <globals state="ready"/>    <screen>        <app-bar title="Tap rush"/>        <main>            <stack style="w-full">                <column>                    <@if test="$state == 'ready'">                        <text>How many taps in 10 seconds?</text>                        <button @click="$state = 'playing'">Start</button>                    <@elseif test="$state == 'playing'">                        <countdown seconds="10"                                   format="ss"                                   on-done="$state = 'done'"/>                    <@else>                        <text>Time's up!</text>                        <button @click="$state = 'ready'">Again</button>                    </@if>                </column>            </stack>        </main>    </screen></app>
Step 4 on a phone: Three screens in one Step 4 on a phone, dark: Three screens in one
Step 4, drawn by the engine from the snippet beside it.

Step 5 of 8

Count the taps

A second global, score. Start resets it, and while playing, a column you tap runs $score++ and shows the score with @text. The done screen says how many.

app.ham · step 58 new lines
<app>    <config primary_color="red"/>    <globals state="ready"             score="0"/>    <screen>        <app-bar title="Tap rush"/>        <main>            <stack style="w-full">                <column>                    <@if test="$state == 'ready'">                        <text>How many taps in 10 seconds?</text>                        <button @click="$score = 0; $state = 'playing'">Start</button>                    <@elseif test="$state == 'playing'">                        <countdown seconds="10"                                   format="ss"                                   on-done="$state = 'done'"/>                        <column @click="$score++">                            <text @text="$score"/>                            <text>TAP</text>                        </column>                    <@else>                        <text>@{$score} taps!</text>                        <button @click="$state = 'ready'">Again</button>                    </@if>                </column>            </stack>        </main>    </screen></app>
Step 5 on a phone: Count the taps Step 5 on a phone, dark: Count the taps
Step 5, drawn by the engine from the snippet beside it.

Step 6 of 8

Remember the best

<globals persist best="0"/> declares $best and keeps it across restarts. When the countdown ends, $best = max($best, $score) keeps the higher of the two, and the done screen says whether you beat it.

app.ham · step 69 new lines
<app>    <config primary_color="red"/>    <globals state="ready"             score="0"/>    <globals persist             best="0"/>    <screen>        <app-bar title="Tap rush"/>        <main>            <stack style="w-full">                <column>                    <text>Best @{$best}</text>                    <@if test="$state == 'ready'">                        <text>How many taps in 10 seconds?</text>                        <button @click="$score = 0; $state = 'playing'">Start</button>                    <@elseif test="$state == 'playing'">                        <countdown seconds="10"                                   format="ss"                                   on-done="$state = 'done'; $best = max($best, $score)"/>                        <column @click="$score++">                            <text @text="$score"/>                            <text>TAP</text>                        </column>                    <@else>                        <text>@{$score} taps!</text>                        <text>                            @{$score >= $best ? 'A new best.' : 'Your best is ' + $best + '.'}                        </text>                        <button @click="$state = 'ready'">Again</button>                    </@if>                </column>            </stack>        </main>    </screen></app>
Step 6 on a phone: Remember the best Step 6 on a phone, dark: Remember the best
Step 6, drawn by the engine from the snippet beside it.

Step 7 of 8

Celebrate

Now the motion:

  • The stack's second layer is <particles preset="confetti">, stretched over the whole game. count="0" keeps it empty until #party.burst throws 160 pieces of confetti, which the countdown does at zero.
  • Each tap runs #pad.animate:punch-110-120: the circle swells to 110% and back in 120 milliseconds.
  • haptic:light on every tap and haptic:success at the end, so you feel the game too.
app.ham · step 710 new lines
<app>    <config primary_color="red"/>    <globals state="ready"             score="0"/>    <globals persist             best="0"/>    <screen>        <app-bar title="Tap rush"/>        <main>            <stack style="w-full">                <column>                    <text>Best @{$best}</text>                    <@if test="$state == 'ready'">                        <text>How many taps in 10 seconds?</text>                        <button @click="$score = 0; $state = 'playing'">Start</button>                    <@elseif test="$state == 'playing'">                        <countdown seconds="10"                                   format="ss"                                   on-done="$state = 'done'; $best = max($best, $score); #party.burst; haptic:success"/>                        <column id="pad"                                @click="$score++; #pad.animate:punch-110-120; haptic:light">                            <text @text="$score"/>                            <text>TAP</text>                        </column>                    <@else>                        <text>@{$score} taps!</text>                        <text>                            @{$score >= $best ? 'A new best.' : 'Your best is ' + $best + '.'}                        </text>                        <button @click="$state = 'ready'">Again</button>                    </@if>                </column>                <particles id="party"                           preset="confetti"                           count="0"                           burst="160"                           style="inset-0"/>            </stack>        </main>    </screen></app>
Step 7 on a phone: Celebrate Step 7 on a phone, dark: Celebrate
Step 7, drawn by the engine from the snippet beside it.

Step 8 of 8

Style it

The tap target becomes a 220-point circle (w-220 h-220 rounded-full) fading red to orange, with the score in huge white type, and press:scale-95 sinks it under your finger. The countdown is big and red, the start and done screens get large type and full-width pill buttons, and the best score gets a trophy.

That's a game: three states, a countdown, a counter that punches, and confetti, with nothing running but the phone.

app.ham · step 830 new lines
<app>    <config primary_color="red"/>    <globals state="ready"             score="0"/>    <globals persist             best="0"/>    <screen>        <app-bar title="Tap rush"/>        <main>            <stack style="w-full">                <column style="w-full p-24 gap-24 items-center">                    <row style="gap-6 items-center">                        <icon name="emoji_events amber"/>                        <text style="font-bold">Best @{$best}</text>                    </row>                    <@if test="$state == 'ready'">                        <text style="font-size-32 font-bold text-center">                            How many taps in 10 seconds?                        </text>                        <button @click="$score = 0; $state = 'playing'"                                variant="filled"                                icon="play_arrow"                                style="w-full rounded-full">Start</button>                    <@elseif test="$state == 'playing'">                        <countdown seconds="10"                                   format="ss"                                   on-done="$state = 'done'; $best = max($best, $score); #party.burst; haptic:success"                                   style="font-size-56 text-red"/>                        <column id="pad"                                @click="$score++; #pad.animate:punch-110-120; haptic:light"                                style="w-220 h-220 rounded-full items-center justify-center gradient-tl-red-orange-br shadow-xl press:scale-95">                            <text style="text-white font-size-72 font-bold"                                  @text="$score"/>                            <text style="text-white opacity-80 font-sm">TAP</text>                        </column>                    <@else>                        <text style="font-size-32 font-bold text-center">@{$score} taps!</text>                        <text style="muted">                            @{$score >= $best ? 'A new best.' : 'Your best is ' + $best + '.'}                        </text>                        <button @click="$state = 'ready'"                                variant="filled"                                icon="replay"                                style="w-full rounded-full">Again</button>                    </@if>                </column>                <particles id="party"                           preset="confetti"                           count="0"                           burst="160"                           style="inset-0"/>            </stack>        </main>    </screen></app>
Step 8 on a phone: Style it Step 8 on a phone, dark: Style it
Step 8, mid-game, at 37 taps, drawn by the engine from the snippet beside it.

This page is also Markdown, and all of HAM is in llms.txt.