Skip to content
loseta

Recipes

Form

A form is a composition: .fieldset for the page, .fieldfor each control, native inputs for state and .btn for actions.

Recipe, not a registry item. Install the composition pieces withloseta add field input checkbox radio button label. Validation and submission remain yours.

Account form

Default

This name appears on your public profile.

Plan

Receive an email when a new component ships.

<div class="fieldset" style="max-width: 28rem">
  <div class="field">
    <label class="label" for="recipe-form-name">Display name</label>
    <input class="input" id="recipe-form-name" name="name" type="text" value="Ada Lovelace" autocomplete="name">
    <p>This name appears on your public profile.</p>
  </div>
  <div class="field">
    <label class="label" for="recipe-form-email">Email</label>
    <input class="input" id="recipe-form-email" name="email" type="email" value="ada@example.com" autocomplete="email">
  </div>
  <fieldset class="field">
    <legend class="label">Plan</legend>
    <div role="radiogroup" aria-label="Plan" style="display: flex; flex-direction: column; gap: 0.5rem">
      <label class="label">
        <input class="radio" type="radio" name="plan" value="starter" checked>
        Starter
      </label>
      <label class="label">
        <input class="radio" type="radio" name="plan" value="pro">
        Pro
      </label>
    </div>
  </fieldset>
  <div class="field" data-orientation="horizontal">
    <section>
      <label class="label" for="recipe-form-updates">Product updates</label>
      <p>Receive an email when a new component ships.</p>
    </section>
    <input class="checkbox" type="checkbox" id="recipe-form-updates" name="updates" checked>
  </div>
  <div style="display: flex; flex-wrap: wrap; gap: 0.5rem">
    <button type="button" class="btn">Create account</button>
    <button type="button" class="btn" data-variant="outline">Cancel</button>
  </div>
</div>

Invalid state

Native validity is not enough on its own: mark the control witharia-invalid="true" and render the message with role="alert". The field turns destructive and the message is announced when it appears.

Invalid

<div class="field" style="max-width: 22rem">
  <label class="label" for="recipe-form-username">Username</label>
  <input class="input" id="recipe-form-username" name="username" value="invalid name" aria-invalid="true" aria-describedby="recipe-form-username-error">
  <p id="recipe-form-username-error" role="alert">Username may only contain letters and numbers.</p>
</div>

Submission

Put the composition in a native <form> and let the browser submit it, or intercept submit in your client. The registry does not provide a submit handler, a schema validator or a reset behavior.

html
<form class="fieldset" action="/settings" method="post">
  <div class="field">
    <label class="label" for="email">Email</label>
    <input class="input" id="email" name="email" type="email" required>
  </div>
  <button class="btn" type="submit">Save</button>
</form>

Composition notes

  • Use one <label> per control and connect it with forand id. A placeholder is not a label.
  • Use <fieldset> and <legend> for radio and checkbox groups; role="radiogroup" plus an accessible name also works.
  • Horizontal rows use data-orientation="horizontal"; responsive rows use"responsive".
  • Error text goes in role="alert". Do not rely on color alone; the text must say what failed.

loseta is MIT licensed. Built with native CSS, no runtime. Inspired byshadcn/ui.