Horizontal form
A form layout with labels on the left and fields on the right, for settings and detail screens.
Form layout zubazar/ui · free (MIT)
Basic usage
BLADE
Split each row into two columns with grid sm:grid-cols-[10rem_1fr] and match the label's for to the field's name.
<form class="space-y-4">
<div class="grid items-center gap-2 sm:grid-cols-[10rem_1fr]">
<label for="customer_name" class="text-sm font-medium text-body">Customer name</label>
<zb:input name="customer_name" value="Ayşe Yılmaz" />
</div>
<div class="grid items-center gap-2 sm:grid-cols-[10rem_1fr]">
<label for="customer_email" class="text-sm font-medium text-body">Email</label>
<zb:input name="customer_email" type="email" value="ayse.yilmaz@example.com" />
</div>
</form>
| Prop | Values |
|---|---|
sm:grid-cols-[10rem_1fr] | Width of the label column |
for / name | Links the label to the field |
In a card
BLADE
Leave the first cell of the button row empty (<span></span>); the buttons line up with the fields.
<zb:card title="Product details">
<form class="space-y-4">
<div class="grid items-center gap-2 sm:grid-cols-[10rem_1fr]">
<label for="product_name" class="text-sm font-medium text-body">Product name</label>
<zb:input name="product_name" value="Wireless headphones" />
</div>
<div class="grid items-center gap-2 sm:grid-cols-[10rem_1fr]">
<label for="product_sku" class="text-sm font-medium text-body">SKU</label>
<zb:input name="product_sku" value="WHP-02" />
</div>
<div class="grid items-center gap-2 sm:grid-cols-[10rem_1fr]">
<label for="product_category" class="text-sm font-medium text-body">Category</label>
<zb:select name="product_category" :options="['1' => 'Electronics', '2' => 'Accessories']" />
</div>
<div class="grid gap-2 sm:grid-cols-[10rem_1fr]">
<span></span>
<div class="flex gap-2"><zb:button type="submit">Save</zb:button><zb:button variant="white">Cancel</zb:button></div>
</div>
</form>
</zb:card>
Multi-line fields and options
BLADE
For tall fields align the row to the top with items-start and give the label sm:pt-2.5.
<zb:card title="Order settings">
<div class="space-y-4">
<div class="grid items-start gap-2 sm:grid-cols-[10rem_1fr]">
<label for="setting_note" class="text-sm font-medium text-body sm:pt-2.5">Invoice note</label>
<zb:textarea name="setting_note" rows="3" />
</div>
<div class="grid items-start gap-2 sm:grid-cols-[10rem_1fr]">
<span class="text-sm font-medium text-body">Notifications</span>
<div class="flex flex-col gap-3">
<zb:switch name="setting_sms" label="Send SMS" checked />
<zb:switch name="setting_email" label="Send email" />
</div>
</div>
</div>
</zb:card>
| Prop | Values |
|---|---|
items-start | Aligns the row to the top |
sm:pt-2.5 | Moves the label down to the field's first line |
Required field, hint and error
BLADE
In this layout add the required star to the label yourself; the hint and the error show below the field, in the right column.
<div class="space-y-4">
<div class="grid items-start gap-2 sm:grid-cols-[10rem_1fr]">
<label for="code" class="text-sm font-medium text-body sm:pt-2.5">SKU <span class="text-danger-line">*</span></label>
<zb:input name="code" value="WHP-01" required />
</div>
<div class="grid items-start gap-2 sm:grid-cols-[10rem_1fr]">
<label for="capacity" class="text-sm font-medium text-body sm:pt-2.5">Daily capacity</label>
<zb:input name="capacity" type="number" value="40" hint="Maximum number of orders that can ship in a day." />
</div>
</div>
| Prop | Values |
|---|---|
required | Passed to the field; add the asterisk to the label by hand |
hint | Below the field, in the right column |
Developer notes
- On small screens the labels move above the fields.
- Use the fields without
label;zb:inputtakes its id fromnamewhen none is given, and shows the star only with its ownlabel.