Form Validation

Process of checking input correctness.

html

<div class="fv fv--error" role="alert">
  <p class="fv__title">Please fix 2 errors</p>
  <p class="fv__message">Email and password are required.</p>
  <label class="fv__field">
    <span class="fv__label">Email</span>
    <input class="fv__input" type="email" style="--accent:#BFD9F2;" aria-invalid="true">
  </label>
</div>
<style>
.fv { font: 14px system-ui, sans-serif; color: #241430; max-width: 300px; padding: 12px 14px; border-radius: 10px; border: 1.5px solid; }
.fv--error { background: #E8A02015; border-color: #E8A020; }
.fv--success { background: #A8E6C120; border-color: #A8E6C1; }
.fv--warning { background: #F5C2E020; border-color: #F5C2E0; }
.fv__title { margin: 0 0 4px; font-weight: 600; }
.fv__message { margin: 0 0 10px; font-size: 13px; }
.fv__field { display: block; }
.fv__label { display: block; margin-bottom: 4px; font-size: 12px; font-weight: 500; }
.fv__input { width: 100%; box-sizing: border-box; padding: 8px 10px; font: inherit; background: #FAF7F2; border: 1.5px solid #24143040; border-radius: 6px; }
.fv__input:focus-visible { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 35%, transparent); }
</style>

tailwind

<div role="alert" class="fv-tw fv-tw--error font-sans text-sm text-[#241430] max-w-[300px] px-3.5 py-3 rounded-[10px] border-[1.5px]">
  <p class="m-0 mb-1 font-semibold">Please fix 2 errors</p>
  <p class="m-0 mb-2.5 text-[13px]">Email and password are required.</p>
  <label class="block">
    <span class="block mb-1 text-xs font-medium">Email</span>
    <input type="email" aria-invalid="true" class="w-full box-border px-2.5 py-2 bg-[#FAF7F2] border-[1.5px] border-[#24143040] rounded-md focus-visible:outline-none" style="border-color:#BFD9F2;">
  </label>
</div>
<style>
.fv-tw--error { background: #E8A02015; border-color: #E8A020; }
.fv-tw--success { background: #A8E6C120; border-color: #A8E6C1; }
.fv-tw--warning { background: #F5C2E020; border-color: #F5C2E0; }
</style>

react

export function FormValidation({
  title = "Please fix 2 errors",
  message = "Email and password are required.",
  status = "error",
  accent = "#BFD9F2",
}) {
  const palette = { error: "#E8A020", success: "#A8E6C1", warning: "#F5C2E0" };
  const c = palette[status] ?? palette.error;
  return (
    <div role="alert" style={{
      fontFamily: "system-ui, sans-serif", fontSize: 14, color: "#241430", maxWidth: 300,
      padding: "12px 14px", borderRadius: 10, border: `1.5px solid ${c}`, background: `${c}20`,
    }}>
      <p style={{ margin: "0 0 4px", fontWeight: 600 }}>{title}</p>
      <p style={{ margin: "0 0 10px", fontSize: 13 }}>{message}</p>
      <label style={{ display: "block" }}>
        <span style={{ display: "block", marginBottom: 4, fontSize: 12, fontWeight: 500 }}>Email</span>
        <input type="email" aria-invalid="true" style={{
          width: "100%", boxSizing: "border-box", padding: "8px 10px", font: "inherit",
          background: "#FAF7F2", border: `1.5px solid ${accent}`, borderRadius: 6,
        }} />
      </label>
    </div>
  );
}