Search Input

Search-specific input.

html

<label class="sr" for="sr-1">
  <span class="sr__label">Search</span>
  <span class="sr__row">
    <span class="sr__icon" aria-hidden="true">&#128269;</span>
    <input class="sr__input" id="sr-1" type="search" placeholder="Search the site" style="--accent:#A8E6C1;border-radius:999px;">
    <span class="sr__clear" role="button" tabindex="0" aria-label="Clear search">&#10005;</span>
  </span>
</label>
<style>
.sr { display: block; font: 14px system-ui, sans-serif; color: #241430; max-width: 260px; }
.sr__label { display: block; margin-bottom: 6px; font-weight: 500; }
.sr__row { position: relative; display: block; }
.sr__icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); font-size: 13px; }
.sr__input { width: 100%; box-sizing: border-box; padding: 10px 34px 10px 34px; font: inherit; color: #241430; background: #FAF7F2; border: 1.5px solid #24143040; }
.sr__input:focus-visible { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 35%, transparent); }
.sr__clear { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); cursor: pointer; color: #24143080; }
</style>

tailwind

<label class="block max-w-[260px] font-sans text-sm text-[#241430]" for="sr-tw-1">
  <span class="block mb-1.5 font-medium">Search</span>
  <span class="relative block">
    <span aria-hidden="true" class="absolute left-3 top-1/2 -translate-y-1/2 text-[13px]">&#128269;</span>
    <input id="sr-tw-1" type="search" placeholder="Search the site" class="w-full box-border pl-[34px] pr-[34px] py-2.5 bg-[#FAF7F2] border-[1.5px] border-[#24143040] focus-visible:outline-none" style="border-radius:999px;border-color:#A8E6C1;">
    <span role="button" tabindex="0" aria-label="Clear search" class="absolute right-3 top-1/2 -translate-y-1/2 cursor-pointer text-[#24143080]">&#10005;</span>
  </span>
</label>

react

export function SearchInput({
  label = "Search",
  placeholder = "Search the site",
  showClear = true,
  accent = "#A8E6C1",
  radius = 999,
}) {
  return (
    <label style={{ display: "block", maxWidth: 260, fontFamily: "system-ui, sans-serif", fontSize: 14, color: "#241430" }}>
      <span style={{ display: "block", marginBottom: 6, fontWeight: 500 }}>{label}</span>
      <span style={{ position: "relative", display: "block" }}>
        <span aria-hidden="true" style={{ position: "absolute", left: 12, top: "50%", transform: "translateY(-50%)", fontSize: 13 }}>🔍</span>
        <input type="search" placeholder={placeholder} style={{
          width: "100%", boxSizing: "border-box", padding: "10px 34px", font: "inherit", color: "#241430",
          background: "#FAF7F2", border: `1.5px solid ${accent}`, borderRadius: radius,
        }} />
        {showClear && (
          <span role="button" tabIndex={0} aria-label="Clear search" style={{ position: "absolute", right: 12, top: "50%", transform: "translateY(-50%)", cursor: "pointer", color: "#24143080" }}>
            ✕
          </span>
        )}
      </span>
    </label>
  );
}