Docs / Smart Forms

Smart Forms

vel-src: state-machine.css

CSS-only form validation using :has() with :valid and :invalid. Labels change color, error messages appear, and borders react — zero JavaScript required.

ClassProperties
vel-smart-formForm container with CSS validation wired via :has()
vel-fieldField group (label + input + hint/error messages)
vel-field-labelLabel that reacts to validity state
vel-field-inputInput with live validity border/ring feedback
vel-field-hintHint text (hidden when field is touched)
vel-field-errorError message (shown when :invalid)
vel-field-okSuccess message (shown when :valid)
vel-form-submitSubmit button — auto-disabled (opacity 0.5, pointer-events none) when form has invalid inputs

Examples

Live validation — type in the fields to see CSS react

At least 2 characters Name must be at least 2 characters Looks good!
We'll never share your email Enter a valid email address Valid email!
example.html
<form class="vel-smart-form" style="max-width:360px;display:grid;gap:1.25rem">
  <div class="vel-field">
    <label class="vel-field-label" for="sf-name">Full name</label>
    <input class="vel-field-input" type="text" id="sf-name" placeholder="Jane Smith" minlength="2" required />
    <span class="vel-field-hint">At least 2 characters</span>
    <span class="vel-field-error">Name must be at least 2 characters</span>
    <span class="vel-field-ok">Looks good!</span>
  </div>
  <div class="vel-field">
    <label class="vel-field-label" for="sf-email">Email address</label>
    <input class="vel-field-input" type="email" id="sf-email" placeholder="jane@example.com" required />
    <span class="vel-field-hint">We'll never share your email</span>
    <span class="vel-field-error">Enter a valid email address</span>
    <span class="vel-field-ok">Valid email!</span>
  </div>
  <button type="submit" class="vel-btn vel-btn-primary">Submit</button>
</form>

Required field — border turns red when left empty and touched

Include https:// Enter a valid URL starting with https:// Valid URL!
example.html
<form class="vel-smart-form" style="max-width:360px;display:grid;gap:1rem">
  <div class="vel-field">
    <label class="vel-field-label" for="sf-url">Website URL</label>
    <input class="vel-field-input" type="url" id="sf-url" placeholder="https://example.com" required />
    <span class="vel-field-hint">Include https://</span>
    <span class="vel-field-error">Enter a valid URL starting with https://</span>
    <span class="vel-field-ok">Valid URL!</span>
  </div>
</form>