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.

ClassDoes what
labelBlock label with spacing for the control it wraps
blockOn 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>

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>

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>

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.

Same markup in both builds
<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>

A message form

Two short fields side by side, a message box, consent, and a send button closing the card.

Same markup in both builds
<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>