# Layout and styling

Build a boarding pass from the smallest app: a card in two parts, rows and columns inside it, then spacing, alignment, color and type.

HAM lays out a screen the way you'd sketch it: things stacked in a `<column>`, side by side in a `<row>`, grouped on a `<card>`. Then the `style` attribute spaces, aligns, colors and sizes them with short tokens, much like Tailwind's. Everything is drawn by the platform's own layout, so it scrolls, resizes and follows the phone's text size like any native screen.

This guide builds a boarding pass, from the outside in: the card first, then what's on it, then how it looks.

## Step 1: 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>`.

```ham
<app>
    <screen>
        <main>
            <text>Hello</text>
        </main>
    </screen>
</app>
```

## Step 2: Add a title bar and a color

`<app-bar>` puts the screen's title across the top, and `<config primary_color="teal">` sets the app's color. Use a named color like `teal`, `amber` or `rose`.

```ham
<app>
    <config primary_color="teal"/>
    <screen>
        <app-bar title="Boarding pass"/>
        <main>
            <text>Hello</text>
        </main>
    </screen>
</app>
```

## Step 3: Start with the card

Build from the outside in. A `<column>` holds the page, a `<card>` is the pass, and the pass has two parts, each a `<column>`: the top for the airline and the route, the bottom for the details. For now each part holds one line, to show where things go.

```ham
<app>
    <config primary_color="teal"/>
    <screen>
        <app-bar title="Boarding pass"/>
        <main>
            <column>
                <card>
                    <column>
                        <text>HYPE AIR</text>
                    </column>
                    <column>
                        <text>Maya Chen</text>
                    </column>
                </card>
            </column>
        </main>
    </screen>
</app>
```

## Step 4: Fill the top

The top gets two `<row>`s, which lay things out side by side. The first holds the airline and the class. The second holds the route: a `<column>` for where you leave from (the code over the city), a plane `<icon>`, and a `<column>` for where you land.

```ham
<app>
    <config primary_color="teal"/>
    <screen>
        <app-bar title="Boarding pass"/>
        <main>
            <column>
                <card>
                    <column>
                        <row>
                            <text>HYPE AIR</text>
                            <text>Economy</text>
                        </row>
                        <row>
                            <column>
                                <text>LIS</text>
                                <text>Lisbon</text>
                            </column>
                            <icon name="flight size-32"/>
                            <column>
                                <text>OPO</text>
                                <text>Porto</text>
                            </column>
                        </row>
                    </column>
                    <column>
                        <text>Maya Chen</text>
                    </column>
                </card>
            </column>
        </main>
    </screen>
</app>
```

## Step 5: Fill the bottom

The bottom gets a row of four small columns, each a label over its value: flight, gate, seat and boarding time. A `<divider>` draws a line under them. Then the passenger's name, beside a `<qr>` code drawn on the phone from `value`: nothing is downloaded.

```ham
<app>
    <config primary_color="teal"/>
    <screen>
        <app-bar title="Boarding pass"/>
        <main>
            <column>
                <card>
                    <column>
                        <row>
                            <text>HYPE AIR</text>
                            <text>Economy</text>
                        </row>
                        <row>
                            <column>
                                <text>LIS</text>
                                <text>Lisbon</text>
                            </column>
                            <icon name="flight size-32"/>
                            <column>
                                <text>OPO</text>
                                <text>Porto</text>
                            </column>
                        </row>
                    </column>
                    <column>
                        <row>
                            <column>
                                <text>Flight</text>
                                <text>HA 204</text>
                            </column>
                            <column>
                                <text>Gate</text>
                                <text>12</text>
                            </column>
                            <column>
                                <text>Seat</text>
                                <text>14C</text>
                            </column>
                            <column>
                                <text>Boards</text>
                                <text>09:40</text>
                            </column>
                        </row>
                        <divider/>
                        <row>
                            <column>
                                <text>Passenger</text>
                                <text>Maya Chen</text>
                            </column>
                            <qr value="HA204 LIS OPO 14C CHEN/MAYA"
                                size="96"
                                color="black"
                                background="white"/>
                        </row>
                    </column>
                </card>
            </column>
        </main>
    </screen>
</app>
```

## Step 6: Space and align it

Now the layout tokens, still without color:

- `p-20 gap-16` pads each part and spaces what's in it; `w-full` makes rows and columns as wide as their parent.
- `justify-between` pushes a row's first and last items to its two ends, and `items-center` lines them up across.
- `flex="1"` makes the two airport columns share the row's width equally, so the plane sits in the middle, and `items-end` lines the destination up on the right.

```ham
<app>
    <config primary_color="teal"/>
    <screen>
        <app-bar title="Boarding pass"/>
        <main>
            <column style="w-full p-20">
                <card>
                    <column style="w-full p-20 gap-16">
                        <row style="w-full justify-between items-center">
                            <text>HYPE AIR</text>
                            <text>Economy</text>
                        </row>
                        <row style="w-full items-center">
                            <column flex="1">
                                <text>LIS</text>
                                <text>Lisbon</text>
                            </column>
                            <icon name="flight size-32"/>
                            <column flex="1"
                                    style="items-end">
                                <text>OPO</text>
                                <text>Porto</text>
                            </column>
                        </row>
                    </column>
                    <column style="w-full p-20 gap-16">
                        <row style="w-full justify-between">
                            <column>
                                <text>Flight</text>
                                <text>HA 204</text>
                            </column>
                            <column>
                                <text>Gate</text>
                                <text>12</text>
                            </column>
                            <column>
                                <text>Seat</text>
                                <text>14C</text>
                            </column>
                            <column>
                                <text>Boards</text>
                                <text>09:40</text>
                            </column>
                        </row>
                        <divider/>
                        <row style="w-full justify-between items-center">
                            <column>
                                <text>Passenger</text>
                                <text>Maya Chen</text>
                            </column>
                            <qr value="HA204 LIS OPO 14C CHEN/MAYA"
                                size="96"
                                color="black"
                                background="white"/>
                        </row>
                    </column>
                </card>
            </column>
        </main>
    </screen>
</app>
```

## Step 7: Color and type

Last, the look:

- `gradient-tl-teal-cyan-br` fills the top with a teal-to-cyan fade, and `text-white` turns its text white.
- `font-size-40 font-bold` makes the airport codes big; `tracking-widest` spaces out the airline's letters; `muted font-xs` makes the labels small and quiet.
- `rotate-90` turns the plane to point along the route.
- `p-0 gap-0 rounded-3xl shadow-xl` lets the two parts fill the card edge to edge, rounds its corners and lifts it off the page.

That's a boarding pass: a card, two columns, a few rows, and the style tokens that make it look like one.

```ham
<app>
    <config primary_color="teal"/>
    <screen>
        <app-bar title="Boarding pass"/>
        <main>
            <column style="w-full p-20">
                <card style="w-full p-0 gap-0 rounded-3xl shadow-xl">
                    <column style="w-full p-20 gap-16 gradient-tl-teal-cyan-br">
                        <row style="w-full justify-between items-center">
                            <text style="text-white font-bold tracking-widest">HYPE AIR</text>
                            <text style="text-white opacity-80 font-sm">Economy</text>
                        </row>
                        <row style="w-full items-center">
                            <column flex="1">
                                <text style="text-white font-size-40 font-bold">LIS</text>
                                <text style="text-white opacity-80 font-sm">Lisbon</text>
                            </column>
                            <icon name="flight size-32 white"
                                  style="rotate-90"/>
                            <column flex="1"
                                    style="items-end">
                                <text style="text-white font-size-40 font-bold">OPO</text>
                                <text style="text-white opacity-80 font-sm">Porto</text>
                            </column>
                        </row>
                    </column>
                    <column style="w-full p-20 gap-16">
                        <row style="w-full justify-between">
                            <column>
                                <text style="muted font-xs">Flight</text>
                                <text style="font-bold">HA 204</text>
                            </column>
                            <column>
                                <text style="muted font-xs">Gate</text>
                                <text style="font-bold">12</text>
                            </column>
                            <column>
                                <text style="muted font-xs">Seat</text>
                                <text style="font-bold">14C</text>
                            </column>
                            <column>
                                <text style="muted font-xs">Boards</text>
                                <text style="font-bold">09:40</text>
                            </column>
                        </row>
                        <divider color="grey-300"/>
                        <row style="w-full justify-between items-center">
                            <column>
                                <text style="muted font-xs">Passenger</text>
                                <text style="font-lg font-bold">Maya Chen</text>
                            </column>
                            <qr value="HA204 LIS OPO 14C CHEN/MAYA"
                                size="96"
                                color="black"
                                background="white"/>
                        </row>
                    </column>
                </card>
            </column>
        </main>
    </screen>
</app>
```

All of HAM, for AI tools: https://hypeapps.dev/llms.txt
