---
title: "Form"
description: "Form component - form layouts with validation, error messages, and accessibility."
slug: "form"
---

import { DocPage, PageHeader, SkillPanel, SourceFiles, SourceNote, StatesSection, CodeBlock, Demo, DemoCode, ChangelogEntries, ArchBody, StatsClaim, StatsCards, PageOverlay, DocText, DocLink, H2, SkillField, SkillText, SkillRow, SkillGrid, Variant, ApiPill, Dim, CodeCard, TableCard } from "../../lib/components/index";

<DocPage meta={meta}>

<PageHeader slug="form" title="Form" component="form">
  Consistent field layout for forms. Built on native <code>&lt;form&gt;</code> with <code>.form-field</code> spacing, <code>.form-field-inline</code> for checkbox/switch rows, <code>.form-field-row</code> for notification-style items, and <code>.form-fieldset</code> for grouped fields.
</PageHeader>

<SkillPanel component="form">
  <SkillField label="Native basis">
<SkillText><code>&lt;form&gt;</code> element with consistent field layout using Label, Input, and description/error helpers. Composes with all form control components.</SkillText>
  </SkillField>

  <SkillField label="Web Platform APIs">
<SkillRow>
    <ApiPill href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/form" title="native form with submission, validation, and reset"><code>&lt;form&gt;</code></ApiPill>
    <ApiPill href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/fieldset" title="groups related fields"><code>&lt;fieldset&gt;</code></ApiPill>
    <ApiPill href="https://developer.mozilla.org/en-US/docs/Web/HTML/Constraint_validation" title="native browser validation"><code>Constraint Validation API</code></ApiPill>
    <ApiPill href="https://developer.mozilla.org/en-US/docs/Web/CSS/:user-invalid" title="post-interaction validation styling"><code>:user-valid / :user-invalid</code></ApiPill>
    <ApiPill href="https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-describedby" title="connects descriptions and errors to inputs"><code>aria-describedby</code></ApiPill>
    <ApiPill href="https://developer.mozilla.org/en-US/docs/Web/API/FormData" title="native form serialization"><code>FormData</code></ApiPill>
  </SkillRow>
  </SkillField>

  <SkillField label="Classes">
<SkillRow>
    <code>.form</code>
    <code>.form-field</code>
    <code>.form-field-inline</code>
    <code>.form-field-row</code>
    <code>.form-actions</code>
    <code>.form-fieldset</code>
    <code>.form-group</code>
  </SkillRow>
  </SkillField>

  <SkillField label="Data attributes">
<SkillGrid>
    <code>data-orientation="horizontal"</code>
    <span class="text-muted-foreground">On <code>.form-field</code> - places label beside control</span>
    <code>data-invalid</code>
    <span class="text-muted-foreground">On <code>.form-field</code> - marks field as invalid, description turns destructive</span>
    <code>data-disabled</code>
    <span class="text-muted-foreground">On <code>.form-field-row</code> - reduces row opacity</span>
  </SkillGrid>
  </SkillField>

  <SkillField label="Notes">
<SkillText dense>• <code>.form-field</code> provides consistent vertical spacing between fields.</SkillText>
  <SkillText dense>• <code>.form-field-inline</code> aligns checkbox/switch/radio horizontally with their label.</SkillText>
  <SkillText dense>• <code>.form-field-row</code> creates a card-like row for notification-style switch items.</SkillText>
  <SkillText dense>• <code>.form-fieldset</code> styles native <code>&lt;fieldset&gt;</code> with legend and description.</SkillText>
  <SkillText dense>• No JavaScript needed for basic forms - use native Constraint Validation.</SkillText>
  <p class="text-muted-foreground m-0">• Compose with Label, Input, Textarea, Select, Checkbox, Radio, Switch, Slider, etc.</p>
  </SkillField>
</SkillPanel>

```html example label="Default" hint="Simple form with labeled fields and descriptions." previewStyle="justify-content:start;padding:2rem;"
<form class="form">
  <div class="form-field">
    <label class="label" for="name">Username</label>
    <input class="input" type="text" id="name" required aria-describedby="name-desc" />
    <p class="field-description" id="name-desc">This is your public display name.</p>
  </div>
  <div class="form-field">
    <label class="label" for="email">Email</label>
    <input class="input" type="email" id="email" required aria-describedby="email-desc" />
    <p class="field-description" id="email-desc">You can manage email addresses in your settings.</p>
  </div>
  <div class="form-field">
    <label class="label" for="bio">Bio</label>
    <textarea class="textarea" id="bio" aria-describedby="bio-desc"></textarea>
    <p class="field-description" id="bio-desc">You can @mention other users and organizations.</p>
  </div>
  <div class="form-actions">
    <button class="btn" type="submit" data-variant="default">Submit</button>
    <button class="btn" type="reset" data-variant="outline">Reset</button>
  </div>
</form>
```

```html example label="Consistent field heights" hint="Every field control renders the same box height for the same data-size - the Input ladder is the standard (40 / 28 / 32 / 36 / 44 / 52px for default / xs / sm / md / lg / xl), so mixed fields sit on one baseline. The rows below use the shipped grid helpers (grid + grid-cols-4 + gap-4) directly." previewStyle="align-items:flex-start;padding:2rem;"
<form class="form w-full" style="max-width: 46rem" onsubmit="return false;">
  <div class="grid grid-cols-4 gap-4">
    <div class="form-field">
      <label class="label" for="fh-1a">Text</label>
      <input class="input" type="text" id="fh-1a" placeholder="Name" />
    </div>
    <div class="form-field">
      <label class="label" for="fh-1b">Select</label>
      <select class="select" id="fh-1b"
        ><option>Option A</option
        ><option>Option B</option></select
      >
    </div>
    <div class="form-field">
      <label class="label" for="fh-1c">Number</label>
      <div class="number-input w-full"
        ><button type="button" data-action="decrement" aria-label="Decrease">−</button
        ><input type="number" id="fh-1c" value="1" min="0" max="99" step="1" /><button
          type="button"
          data-action="increment"
          aria-label="Increase"
          >+</button
        ></div
      >
    </div>
    <div class="form-field">
      <label class="label" id="fh-1d-label">Combobox</label>
      <div class="combobox">
        <button
          class="btn combobox-trigger"
          type="button"
          data-variant="outline"
          aria-haspopup="listbox"
          aria-expanded="false"
          aria-labelledby="fh-1d-label"
          aria-controls="fh-1d-popover"
        >
          <span class="combobox-value" data-placeholder="Pick…">Pick…</span>
          <svg
            class="combobox-chevron"
            aria-hidden="true"
            width="16"
            height="16"
            viewBox="0 0 24 24"
            fill="none"
            stroke="currentColor"
            stroke-width="2"
          >
            <path d="m7 15 5 5 5-5"></path>
            <path d="m7 9 5-5 5 5"></path>
          </svg>
        </button>
        <div id="fh-1d-popover" class="combobox-content" popover>
          <div class="combobox-listbox" role="listbox" aria-label="Height demo options">
            <div role="option" class="combobox-item" data-value="a" aria-selected="false">Option A</div>
            <div role="option" class="combobox-item" data-value="b" aria-selected="false">Option B</div>
          </div>
        </div>
      </div>
    </div>
  </div>
  <div class="grid grid-cols-4 gap-4">
    <div class="form-field">
      <label class="label" for="fh-2a">Date</label>
      <input class="input date-input" type="date" id="fh-2a" />
    </div>
    <div class="form-field">
      <label class="label" for="fh-2b">Color</label>
      <div class="color-picker w-full"
        ><input type="color" id="fh-2b" value="#3b82f6" /><span class="color-picker-value">#3B82F6</span></div
      >
    </div>
    <div class="form-field">
      <label class="label" for="fh-2c">File</label>
      <input class="file-input" type="file" id="fh-2c" />
    </div>
    <div class="form-field">
      <label class="label" for="fh-2d">Reference</label>
      <input class="input" type="text" id="fh-2d" placeholder="Input" />
    </div>
  </div>
  <div class="grid grid-cols-4 gap-4">
    <div class="form-field">
      <label class="label" for="fh-3a">Text <code>xs</code></label>
      <input class="input" type="text" id="fh-3a" data-size="xs" />
    </div>
    <div class="form-field">
      <label class="label" for="fh-3b">Select <code>xs</code></label>
      <select class="select" id="fh-3b" data-size="xs"
        ><option>A</option></select
      >
    </div>
    <div class="form-field">
      <label class="label" for="fh-3c">Number <code>xs</code></label>
      <div class="number-input w-full" data-size="xs"
        ><button type="button" data-action="decrement" aria-label="Decrease">−</button
        ><input type="number" id="fh-3c" value="1" min="0" max="99" step="1" /><button
          type="button"
          data-action="increment"
          aria-label="Increase"
          >+</button
        ></div
      >
    </div>
    <div class="form-field">
      <label class="label" for="fh-3d">Date <code>xs</code></label>
      <input class="input date-input" type="date" id="fh-3d" data-size="xs" />
    </div>
  </div>
  <div class="grid grid-cols-4 gap-4">
    <div class="form-field">
      <label class="label" for="fh-4a">Text <code>lg</code></label>
      <input class="input" type="text" id="fh-4a" data-size="lg" />
    </div>
    <div class="form-field">
      <label class="label" for="fh-4b">Select <code>lg</code></label>
      <select class="select" id="fh-4b" data-size="lg"
        ><option>A</option></select
      >
    </div>
    <div class="form-field">
      <label class="label" for="fh-4c">Number <code>lg</code></label>
      <div class="number-input w-full" data-size="lg"
        ><button type="button" data-action="decrement" aria-label="Decrease">−</button
        ><input type="number" id="fh-4c" value="1" min="0" max="99" step="1" /><button
          type="button"
          data-action="increment"
          aria-label="Increase"
          >+</button
        ></div
      >
    </div>
    <div class="form-field">
      <label class="label" for="fh-4d">Date <code>lg</code></label>
      <input class="input date-input" type="date" id="fh-4d" data-size="lg" />
    </div>
  </div>
</form>
```

```html example label="Full composition" hint="Comprehensive form composing multiple field types." previewStyle="justify-content:start;padding:2rem;"
<form class="form">
  <div class="form-field">
    <label class="label" for="name">Username</label>
    <input class="input" type="text" id="name" required aria-describedby="name-desc" />
    <p class="field-description" id="name-desc">This is your public display name.</p>
  </div>
  <div class="form-field">
    <label class="label" for="email">Email</label>
    <select class="select" id="email">
      <option>m@example.com</option>
    </select>
  </div>
  <fieldset class="form-fieldset">
    <legend>Notify me about...</legend>
    <div class="form-group">
      <div class="form-field-inline">
        <input class="radio" type="radio" name="notify" id="all" checked />
        <label for="all">All new messages</label>
      </div>
    </div>
  </fieldset>
  <div class="form-field-row">
    <div>
      <label class="label" for="marketing">Marketing emails</label>
      <p class="field-description" id="marketing-desc">Receive emails about new products.</p>
    </div>
    <input class="switch" type="checkbox" role="switch" id="marketing" aria-describedby="marketing-desc" />
  </div>
  <div class="form-actions">
    <button class="btn" type="submit">Submit</button>
  </div>
</form>
```

```html example label="Inline fields" hint="Checkbox and switch aligned with labels." previewStyle="display:flex;flex-direction:column;align-items:flex-start;gap:1.25rem;padding:2rem;"
<div class="form-field-inline">
  <input class="checkbox" type="checkbox" id="terms" />
  <label for="terms">Accept terms and conditions</label>
</div>
<div class="form-field-inline">
  <input class="switch" type="checkbox" role="switch" id="news" />
  <label for="news">Subscribe to newsletter</label>
</div>
```

```html example label="Switch rows (notifications)" hint="Notification-style rows with label, description, and switch - stacked in a .form-group for the gap between them." previewStyle="justify-content:start;padding:2rem;"
<div class="form-group">
  <div class="form-field-row">
    <div>
      <label class="label" for="marketing">Marketing emails</label>
      <p class="field-description" id="marketing-desc">Receive emails about new products, features, and more.</p>
    </div>
    <input class="switch" type="checkbox" role="switch" id="marketing" aria-describedby="marketing-desc" />
  </div>
  <div class="form-field-row">
    <div>
      <label class="label" for="security">Security emails</label>
      <p class="field-description" id="security-desc">Receive emails about your account security.</p>
    </div>
    <input
      class="switch"
      type="checkbox"
      role="switch"
      id="security"
      checked
      disabled
      aria-describedby="security-desc"
    />
  </div>
</div>
```

```html example label="Fieldset grouping" hint="Group related fields with &lt;fieldset&gt; and &lt;legend&gt;." previewStyle="justify-content:start;padding:2rem;"
<fieldset class="form-fieldset">
  <legend>Notify me about...</legend>
  <div class="form-group">
    <div class="form-field-inline">
      <input class="radio" type="radio" name="notify" id="all" checked />
      <label for="all">All new messages</label>
    </div>
    <div class="form-field-inline">
      <input class="radio" type="radio" name="notify" id="direct" />
      <label for="direct">Direct messages and mentions</label>
    </div>
    <div class="form-field-inline">
      <input class="radio" type="radio" name="notify" id="none" />
      <label for="none">Nothing</label>
    </div>
  </div>
</fieldset>
```

```html example label="Horizontal layout" hint="Label placed beside the control with data-orientation='horizontal'." previewStyle="justify-content:start;padding:2rem;"
<div class="form-field" data-orientation="horizontal">
  <label class="label" for="name">Name</label>
  <div>
    <input class="input" type="text" id="name" aria-describedby="name-desc" />
    <p class="field-description" id="name-desc">Your full name for identification.</p>
  </div>
</div>
```

```html example label="Validation with errors" hint="Fields with data-invalid and aria-invalid for error states." previewStyle="justify-content:start;padding:2rem;"
<div class="form-field" data-invalid>
  <label class="label" for="user">Username</label>
  <input class="input" type="text" id="user" aria-invalid="true" aria-describedby="user-err" />
  <p class="field-error" id="user-err" role="alert"> Username must be at least 3 characters. </p>
</div>
```

<SourceFiles component="form" section="css" />

</DocPage>
