1. Docs
  2. Guides

Drawing and media

Build a sketch pad from the smallest app: a canvas, a photo to trace, your own palette of colors, undo and an eraser, and ink that thickens as you slow down.

8 steps · ends in a sketch pad that traces over a photo

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.

Media tags put the phone's own capabilities on screen: <canvas> for drawing, <img> and <video> for pictures and film, <camera> and <audio> for what the phone can capture and play. Each one is a single tag with attributes, and each answers commands from any button: #pad.undo, #pad.clear, #pad.pen.color:teal.

This guide builds a sketch pad that traces over a photo.

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 screen's title across the top, and <config primary_color="amber"> gives every control an amber. Use a named color like amber, teal or rose.

app.ham · step 22 new lines
<app>    <config primary_color="amber"/>    <screen>        <app-bar title="Sketch"/>        <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

Add a canvas

<canvas> is a drawing surface: draw with a finger or a pencil, pinch to zoom and pan. id="pad" names it, so buttons can talk to it later, and w-full h-380 makes it the screen's width and 380 points tall. It comes with its own toolbar of colors and sizes.

app.ham · step 34 new lines
<app>    <config primary_color="amber"/>    <screen>        <app-bar title="Sketch"/>        <main>            <column>                <canvas id="pad"                        style="w-full h-380"/>            </column>        </main>    </screen></app>
Step 3 on a phone: Add a canvas Step 3 on a phone, dark: Add a canvas
Step 3, drawn by the engine from the snippet beside it.

Step 4 of 8

Trace a photo

underlay lays a picture under the canvas, underlay-opacity="0.35" fades it so the ink stands out, and underlay-fit="cover" fills the canvas with it. The photo is a guide only: it's not part of the drawing.

app.ham · step 45 new lines
<app>    <config primary_color="amber"/>    <screen>        <app-bar title="Sketch"/>        <main>            <column>                <canvas id="pad"                        underlay="https://hypeapps.dev/gallery/assets/landscape.jpg"                        underlay-opacity="0.35"                        underlay-fit="cover"                        style="w-full h-380"/>            </column>        </main>    </screen></app>
Step 4 on a phone: Trace a photo Step 4 on a phone, dark: Trace a photo
Step 4, drawn by the engine from the snippet beside it.

Step 5 of 8

Make your own palette

toolbar="false" hides the built-in toolbar, so the app can have its own. A <row> of five round swatches, each a small <column> in a named color. Tapping one runs two commands: #pad.pen picks the pen, and #pad.pen.color:teal sets its color.

app.ham · step 518 new lines
<app>    <config primary_color="amber"/>    <screen>        <app-bar title="Sketch"/>        <main>            <column>                <canvas id="pad"                        toolbar="false"                        underlay="https://hypeapps.dev/gallery/assets/landscape.jpg"                        underlay-opacity="0.35"                        underlay-fit="cover"                        style="w-full h-380"/>                <row style="gap-12">                    <column @click="#pad.pen; #pad.pen.color:black"                            style="w-36 h-36 rounded-full bg-black"/>                    <column @click="#pad.pen; #pad.pen.color:red"                            style="w-36 h-36 rounded-full bg-red"/>                    <column @click="#pad.pen; #pad.pen.color:amber"                            style="w-36 h-36 rounded-full bg-amber"/>                    <column @click="#pad.pen; #pad.pen.color:teal"                            style="w-36 h-36 rounded-full bg-teal"/>                    <column @click="#pad.pen; #pad.pen.color:white"                            style="w-36 h-36 rounded-full bg-white"/>                </row>            </column>        </main>    </screen></app>
Step 5 on a phone: Make your own palette Step 5 on a phone, dark: Make your own palette
Step 5, drawn by the engine from the snippet beside it.

Step 6 of 8

Add the tools

A second row of buttons talking to the pad: #pad.undo, #pad.redo, #pad.eraser and #pad.clear. The pad also publishes what it's doing, and $pad.strokes counts the strokes so far.

app.ham · step 611 new lines
<app>    <config primary_color="amber"/>    <screen>        <app-bar title="Sketch"/>        <main>            <column>                <canvas id="pad"                        toolbar="false"                        underlay="https://hypeapps.dev/gallery/assets/landscape.jpg"                        underlay-opacity="0.35"                        underlay-fit="cover"                        style="w-full h-380"/>                <row style="gap-12">                    <column @click="#pad.pen; #pad.pen.color:black"                            style="w-36 h-36 rounded-full bg-black"/>                    <column @click="#pad.pen; #pad.pen.color:red"                            style="w-36 h-36 rounded-full bg-red"/>                    <column @click="#pad.pen; #pad.pen.color:amber"                            style="w-36 h-36 rounded-full bg-amber"/>                    <column @click="#pad.pen; #pad.pen.color:teal"                            style="w-36 h-36 rounded-full bg-teal"/>                    <column @click="#pad.pen; #pad.pen.color:white"                            style="w-36 h-36 rounded-full bg-white"/>                </row>                <row>                    <button @click="#pad.undo"                            icon="undo"/>                    <button @click="#pad.redo"                            icon="redo"/>                    <button @click="#pad.eraser"                            icon="ink_eraser"/>                    <text flex="1">@{$pad.strokes} strokes</text>                    <button @click="#pad.clear"                            icon="delete">Clear</button>                </row>            </column>        </main>    </screen></app>
Step 6 on a phone: Add the tools Step 6 on a phone, dark: Add the tools
Step 6, drawn by the engine from the snippet beside it.

Step 7 of 8

Get the ink right

The pen gets its own settings: pen-color="black" and pen-width="6" to start, and pen-dynamics="fountain", which makes the line thinner when you draw fast and fuller when you slow down, like a fountain pen.

var-ink remembers which swatch is picked, each swatch sets it, and a check mark with @show marks the one in use. The eraser clears it, since no color is picked.

app.ham · step 737 new lines
<app>    <config primary_color="amber"/>    <screen>        <app-bar title="Sketch"/>        <main>            <column var-ink="black">                <canvas id="pad"                        toolbar="false"                        pen-color="black"                        pen-width="6"                        pen-dynamics="fountain"                        underlay="https://hypeapps.dev/gallery/assets/landscape.jpg"                        underlay-opacity="0.35"                        underlay-fit="cover"                        style="w-full h-380"/>                <row style="gap-12">                    <column @click="#pad.pen; #pad.pen.color:black; $ink = 'black'"                            style="w-36 h-36 rounded-full items-center justify-center bg-black">                        <icon name="check size-sm white"                              @show="$ink == 'black'"/>                    </column>                    <column @click="#pad.pen; #pad.pen.color:red; $ink = 'red'"                            style="w-36 h-36 rounded-full items-center justify-center bg-red">                        <icon name="check size-sm white"                              @show="$ink == 'red'"/>                    </column>                    <column @click="#pad.pen; #pad.pen.color:amber; $ink = 'amber'"                            style="w-36 h-36 rounded-full items-center justify-center bg-amber">                        <icon name="check size-sm black"                              @show="$ink == 'amber'"/>                    </column>                    <column @click="#pad.pen; #pad.pen.color:teal; $ink = 'teal'"                            style="w-36 h-36 rounded-full items-center justify-center bg-teal">                        <icon name="check size-sm white"                              @show="$ink == 'teal'"/>                    </column>                    <column @click="#pad.pen; #pad.pen.color:white; $ink = 'white'"                            style="w-36 h-36 rounded-full items-center justify-center bg-white">                        <icon name="check size-sm black"                              @show="$ink == 'white'"/>                    </column>                </row>                <row>                    <button @click="#pad.undo"                            icon="undo"/>                    <button @click="#pad.redo"                            icon="redo"/>                    <button @click="#pad.eraser; $ink = ''"                            icon="ink_eraser"/>                    <text flex="1">@{$pad.strokes} strokes</text>                    <button @click="#pad.clear"                            icon="delete">Clear</button>                </row>            </column>        </main>    </screen></app>
Step 7 on a phone: Get the ink right Step 7 on a phone, dark: Get the ink right
Step 7, drawn by the engine from the snippet beside it.

Step 8 of 8

Style it

The canvas gets rounded corners and a thin border, the swatches a rim, a shadow and a little press, the buttons an outline, and the stroke count fades back into the row.

That's a sketch pad: one tag for the canvas, and a few rows of buttons that tell it what to do.

app.ham · step 840 new lines
<app>    <config primary_color="amber"/>    <screen>        <app-bar title="Sketch"/>        <main>            <column style="w-full p-16 gap-14"                    var-ink="black">                <canvas id="pad"                        toolbar="false"                        pen-color="black"                        pen-width="6"                        pen-dynamics="fountain"                        underlay="https://hypeapps.dev/gallery/assets/landscape.jpg"                        underlay-opacity="0.35"                        underlay-fit="cover"                        style="w-full h-380 rounded-3xl border border-grey-300"/>                <row style="w-full gap-12 justify-center">                    <column @click="#pad.pen; #pad.pen.color:black; $ink = 'black'; haptic:selection"                            style="w-36 h-36 rounded-full items-center justify-center bg-black border border-grey-300 shadow press:scale-90">                        <icon name="check size-sm white"                              @show="$ink == 'black'"/>                    </column>                    <column @click="#pad.pen; #pad.pen.color:red; $ink = 'red'; haptic:selection"                            style="w-36 h-36 rounded-full items-center justify-center bg-red border border-grey-300 shadow press:scale-90">                        <icon name="check size-sm white"                              @show="$ink == 'red'"/>                    </column>                    <column @click="#pad.pen; #pad.pen.color:amber; $ink = 'amber'; haptic:selection"                            style="w-36 h-36 rounded-full items-center justify-center bg-amber border border-grey-300 shadow press:scale-90">                        <icon name="check size-sm black"                              @show="$ink == 'amber'"/>                    </column>                    <column @click="#pad.pen; #pad.pen.color:teal; $ink = 'teal'; haptic:selection"                            style="w-36 h-36 rounded-full items-center justify-center bg-teal border border-grey-300 shadow press:scale-90">                        <icon name="check size-sm white"                              @show="$ink == 'teal'"/>                    </column>                    <column @click="#pad.pen; #pad.pen.color:white; $ink = 'white'; haptic:selection"                            style="w-36 h-36 rounded-full items-center justify-center bg-white border border-grey-300 shadow press:scale-90">                        <icon name="check size-sm black"                              @show="$ink == 'white'"/>                    </column>                </row>                <row style="w-full gap-8 items-center">                    <button @click="#pad.undo"                            variant="outlined"                            icon="undo"                            style="rounded-full"/>                    <button @click="#pad.redo"                            variant="outlined"                            icon="redo"                            style="rounded-full"/>                    <button @click="#pad.eraser; $ink = ''"                            variant="outlined"                            icon="ink_eraser"                            style="rounded-full"/>                    <text style="muted font-sm text-right"                          flex="1">@{$pad.strokes} strokes</text>                    <button @click="#pad.clear"                            variant="text"                            icon="delete">Clear</button>                </row>            </column>        </main>    </screen></app>
Step 8 on a phone: Style it Step 8 on a phone, dark: Style it
Step 8, drawn by the engine from the snippet beside it.

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