Label
Wrap a control in a label and the spacing, hint text and choice layouts follow. The label is the layout primitive for every form control in this framework.
| Class | Does what |
|---|---|
label | Block label with spacing for the control it wraps |
block | On a label wrapping a radio: renders it as a selectable card |
Label and control
<label class="label">
Email
<input type="email" class="input" placeholder="you@example.com" />
</label>
<label>
Email
<input type="email" placeholder="you@example.com" />
</label>
Hint text
A small after the control becomes a hint, and the control's bottom margin collapses into it.
<label class="label">
Username
<input type="text" class="input" />
<small>Letters, numbers and dashes.</small>
</label>
<label>
Username
<input type="text" />
<small>Letters, numbers and dashes.</small>
</label>
Invalid state
A label's leading p turns error-colored when the control after it is invalid.
<label class="label">
<p>Email</p>
<input type="email" class="input input-error" aria-invalid="true" value="not-an-email" />
<small class="text-error">Enter a valid email address.</small>
</label>
<label>
<p>Email</p>
<input type="email" aria-invalid="true" value="not-an-email" />
<small class="error">Enter a valid email address.</small>
</label>
Classless: <code>aria-invalid="true"</code> drives the error color on its own. <code>.input-error</code> is there for when you cannot set the attribute.
Composition
Common ways to put this together with other components. The general rules are on Composition.
A field with help and an error
Label text, the field, and a line under it. When the value is wrong, the same line becomes the error.
<form style="max-width: 30rem">
<label class="label">
<p>Website</p>
<input class="input" type="url" placeholder="https://" />
<small>Where people can see your work.</small>
</label>
<label class="label">
<p>Email</p>
<input class="input" type="email" value="name@" aria-invalid="true" />
<small>Enter a full email address.</small>
</label>
<label class="label">
<input type="checkbox" class="checkbox" />
Send me a copy
</label>
<button class="btn">Send</button>
</form>
- Controls: the label wraps all three parts and spaces them; the form needs no wrapper between fields.
- States:
aria-invalidon the field turns it and the label text above it to the error colour. - Layout: a checkbox inside a label lays out as a row instead of a stack.
A message form
Two short fields side by side, a message box, consent, and a send button closing the card.
<form class="card">
<div class="flex flip" style="row-gap: 0">
<label class="label" style="flex: 1"><p>Name</p><input class="input" autocomplete="name" /></label>
<label class="label" style="flex: 1"><p>Email</p><input class="input" type="email" autocomplete="email" /></label>
</div>
<label class="label">
<p>Message</p>
<textarea class="textarea" rows="4"></textarea>
<small>A few sentences is plenty.</small>
</label>
<label class="label">
<input type="checkbox" class="checkbox" required />
I agree to be contacted about this request
</label>
<footer class="card-actions flex" style="justify-content: end">
<button class="btn">Send</button>
</footer>
</form>
- Layout: two short fields share a
.flex .fliprow;row-gap: 0keeps them from double-spacing when they stack on a phone. - Controls: the consent checkbox sits right above the action it gates.
- Surface:
.card-actionscloses the card with its own rule, which also absorbs the last field's bottom margin.