Inline Validation

Validation displayed alongside the field.

Username is available.

html

<div class="iv">
  <label class="iv__label" for="iv-1">Username</label>
  <div class="iv__row">
    <input class="iv__input" id="iv-1" type="text" value="clyde_ford" style="--accent:#A8E6C1;" aria-invalid="false" aria-describedby="iv-msg-1">
    <span class="iv__icon" style="--accent:#A8E6C1;" aria-hidden="true">&#10003;</span>
  </div>
  <p class="iv__msg" id="iv-msg-1" style="--accent:#A8E6C1;">Username is available.</p>
</div>
<style>
.iv { font: 14px system-ui, sans-serif; color: #241430; max-width: 260px; }
.iv__label { display: block; margin-bottom: 6px; font-weight: 500; }
.iv__row { position: relative; }
.iv__input { width: 100%; box-sizing: border-box; padding: 10px 34px 10px 12px; font: inherit; color: #241430; background: #FAF7F2; border: 1.5px solid var(--accent); border-radius: 8px; }
.iv__input:focus-visible { outline: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 35%, transparent); }
.iv__icon { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); color: var(--accent); font-weight: 700; }
.iv__msg { margin: 6px 0 0; font-size: 12px; color: var(--accent); }
</style>

tailwind

<div class="font-sans text-sm text-[#241430] max-w-[260px]">
  <label class="block mb-1.5 font-medium" for="iv-tw-1">Username</label>
  <div class="relative">
    <input id="iv-tw-1" type="text" value="clyde_ford" aria-invalid="false" aria-describedby="iv-tw-msg-1"
      class="w-full box-border pl-3 pr-9 py-2.5 bg-[#FAF7F2] border-[1.5px] rounded-lg focus-visible:outline-none" style="border-color:#A8E6C1;">
    <span aria-hidden="true" class="absolute right-2.5 top-1/2 -translate-y-1/2 font-bold" style="color:#A8E6C1;">&#10003;</span>
  </div>
  <p id="iv-tw-msg-1" class="mt-1.5 text-xs" style="color:#A8E6C1;">Username is available.</p>
</div>

react

export function InlineValidation({
  label = "Username",
  value = "clyde_ford",
  message = "Username is available.",
  valid = true,
  accent = "#A8E6C1",
}) {
  return (
    <div style={{ fontFamily: "system-ui, sans-serif", fontSize: 14, color: "#241430", maxWidth: 260 }}>
      <label htmlFor="iv-react-1" style={{ display: "block", marginBottom: 6, fontWeight: 500 }}>{label}</label>
      <div style={{ position: "relative" }}>
        <input id="iv-react-1" type="text" defaultValue={value} aria-invalid={!valid} aria-describedby="iv-react-msg-1" style={{
          width: "100%", boxSizing: "border-box", padding: "10px 34px 10px 12px", font: "inherit", color: "#241430",
          background: "#FAF7F2", border: `1.5px solid ${accent}`, borderRadius: 8,
        }} />
        <span aria-hidden="true" style={{ position: "absolute", right: 10, top: "50%", transform: "translateY(-50%)", color: accent, fontWeight: 700 }}>
          {valid ? "✓" : "✗"}
        </span>
      </div>
      <p id="iv-react-msg-1" style={{ margin: "6px 0 0", fontSize: 12, color: accent }}>{message}</p>
    </div>
  );
}