08 / 28
All 28 in 28 Tailwind CSS Input Fields
- 01Tailwind Floating Label Input
- 02Tailwind Underline Sweep Input
- 03Tailwind Neon Glow Input
- 04Tailwind Frosted Glass Input
- 05Tailwind Notched Outline Input
- 06Tailwind Drawn Border Input
- 07Tailwind Inline Validation Input
- 08Tailwind Search Input With Clear
- 09Tailwind Password Strength Meter
- 10Tailwind OTP Code Input
- 11Tailwind Rotating Placeholder Input
- 12Tailwind Tag Chip Input
- 13Tailwind Phone Input With Country
- 14Tailwind Stepper Number Input
- 15Tailwind File Drop Zone
- 16Tailwind Currency Input
- 17Tailwind Native Date Input
- 18Tailwind Time Range Input
- 19Tailwind Colour Picker Input
- 20Tailwind Voice Search Input
- 21Tailwind Email Suggestion Combobox
- 22Tailwind Auto-Grow Textarea
- 23Tailwind Inline Edit Field
- 24Tailwind Range Slider
- 25Tailwind URL Input With Protocol
- 26Tailwind Credit Card Input
- 27Tailwind Password Toggle Input
- 28Tailwind Brutalist Input
Tailwind Search Input With Clear
A pill search field with a leading magnifier and a trailing clear button that only exists when there is something to clear. type="reset" does the clearing; has-[input:placeholder-shown]: does the hiding.
Untitled UI Pro: 5,000+ React + Tailwind CSS v4 components · from $349 one-time
Untitled UI React · Affiliate link
The code
<div class="tif-08 grid min-h-svh w-full place-items-center bg-tif08-bg px-6 py-14 font-tif08-sans" aria-label="Search input with clear demo">
<form role="search" class="group relative flex w-full max-w-80 items-center gap-1 rounded-full border border-white/10 bg-tif08-field pr-1.5 pl-10 transition-[border-color,box-shadow] duration-200 focus-within:border-tif08-acc focus-within:ring-3 focus-within:ring-tif08-acc/18">
<span class="pointer-events-none absolute left-3.5 grid place-items-center text-tif08-mut transition-colors group-focus-within:text-tif08-acc" aria-hidden="true">
<svg viewBox="0 0 16 16" width="14" height="14"><path fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" d="M11 11l3 3M7 12a5 5 0 1 1 0-10 5 5 0 0 1 0 10z"/></svg>
</span>
<input type="search" name="q" placeholder="Search projects, people, files…" aria-label="Search"
class="min-w-0 flex-1 border-0 bg-transparent py-2.5 text-sm text-tif08-ink outline-none placeholder:text-tif08-mut [&::-webkit-search-cancel-button]:hidden">
<button type="reset" aria-label="Clear search"
class="grid size-11 shrink-0 cursor-pointer place-items-center rounded-full border-0 bg-transparent text-tif08-mut transition-[opacity,background-color,color] duration-150 hover:bg-white/12 hover:text-tif08-ink focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-tif08-acc group-has-[input:placeholder-shown]:pointer-events-none group-has-[input:placeholder-shown]:opacity-0">
<svg viewBox="0 0 12 12" width="10" height="10" aria-hidden="true"><path fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" d="M2 2l8 8M10 2l-8 8"/></svg>
</button>
</form>
</div><div class="tif-08 grid min-h-svh w-full place-items-center bg-tif08-bg px-6 py-14 font-tif08-sans" aria-label="Search input with clear demo">
<form role="search" class="group relative flex w-full max-w-80 items-center gap-1 rounded-full border border-white/10 bg-tif08-field pr-1.5 pl-10 transition-[border-color,box-shadow] duration-200 focus-within:border-tif08-acc focus-within:ring-3 focus-within:ring-tif08-acc/18">
<span class="pointer-events-none absolute left-3.5 grid place-items-center text-tif08-mut transition-colors group-focus-within:text-tif08-acc" aria-hidden="true">
<svg viewBox="0 0 16 16" width="14" height="14"><path fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" d="M11 11l3 3M7 12a5 5 0 1 1 0-10 5 5 0 0 1 0 10z"/></svg>
</span>
<input type="search" name="q" placeholder="Search projects, people, files…" aria-label="Search"
class="min-w-0 flex-1 border-0 bg-transparent py-2.5 text-sm text-tif08-ink outline-none placeholder:text-tif08-mut [&::-webkit-search-cancel-button]:hidden">
<button type="reset" aria-label="Clear search"
class="grid size-11 shrink-0 cursor-pointer place-items-center rounded-full border-0 bg-transparent text-tif08-mut transition-[opacity,background-color,color] duration-150 hover:bg-white/12 hover:text-tif08-ink focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-tif08-acc group-has-[input:placeholder-shown]:pointer-events-none group-has-[input:placeholder-shown]:opacity-0">
<svg viewBox="0 0 12 12" width="10" height="10" aria-hidden="true"><path fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" d="M2 2l8 8M10 2l-8 8"/></svg>
</button>
</form>
</div>@import "tailwindcss";
@theme {
--color-tif08-bg: #12121a;
--color-tif08-bg: oklch(0.19 0.015 285);
--color-tif08-field: #1a1a22;
--color-tif08-field: oklch(0.23 0.015 285);
--color-tif08-ink: #f0eeff;
--color-tif08-ink: oklch(0.95 0.02 290);
--color-tif08-mut: #b8b6d4;
--color-tif08-mut: oklch(0.77 0.03 290);
--color-tif08-acc: #60a5fa;
--color-tif08-acc: oklch(0.73 0.14 255);
--font-tif08-sans: 'Plus Jakarta Sans', system-ui, sans-serif;
}
.tif-08 {
width: 100%;
}
.tif-08 ::selection {
background: var(--color-tif08-acc);
color: #12121a;
}@import "tailwindcss";
@theme {
--color-tif08-bg: #12121a;
--color-tif08-bg: oklch(0.19 0.015 285);
--color-tif08-field: #1a1a22;
--color-tif08-field: oklch(0.23 0.015 285);
--color-tif08-ink: #f0eeff;
--color-tif08-ink: oklch(0.95 0.02 290);
--color-tif08-mut: #b8b6d4;
--color-tif08-mut: oklch(0.77 0.03 290);
--color-tif08-acc: #60a5fa;
--color-tif08-acc: oklch(0.73 0.14 255);
--font-tif08-sans: 'Plus Jakarta Sans', system-ui, sans-serif;
}
.tif-08 {
width: 100%;
}
.tif-08 ::selection {
background: var(--color-tif08-acc);
color: #12121a;
}Setup — do this once per project
Skip this if your project already runs Tailwind v4.
<script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"></script>
<script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"></script>Compiles in the browser — perfect for a CodePen or a quick test, not for production.
npm install tailwindcss @tailwindcss/vite
npm install tailwindcss @tailwindcss/vite// vite.config.js ("type": "module" in package.json)
import { defineConfig } from 'vite'
import tailwindcss from '@tailwindcss/vite'
export default defineConfig({
plugins: [tailwindcss()],
})// vite.config.js ("type": "module" in package.json)
import { defineConfig } from 'vite'
import tailwindcss from '@tailwindcss/vite'
export default defineConfig({
plugins: [tailwindcss()],
})Any v4 setup works — Vite, PostCSS or the CLI. Nothing in this demo is bundler-specific.
@import "tailwindcss";
@theme {
--color-tif08-bg: #12121a;
--color-tif08-bg: oklch(0.19 0.015 285);
--color-tif08-field: #1a1a22;
--color-tif08-field: oklch(0.23 0.015 285);
--color-tif08-ink: #f0eeff;
--color-tif08-ink: oklch(0.95 0.02 290);
--color-tif08-mut: #b8b6d4;
--color-tif08-mut: oklch(0.77 0.03 290);
--color-tif08-acc: #60a5fa;
--color-tif08-acc: oklch(0.73 0.14 255);
--font-tif08-sans: 'Plus Jakarta Sans', system-ui, sans-serif;
}
.tif-08 {
width: 100%;
}
.tif-08 ::selection {
background: var(--color-tif08-acc);
color: #12121a;
}@import "tailwindcss";
@theme {
--color-tif08-bg: #12121a;
--color-tif08-bg: oklch(0.19 0.015 285);
--color-tif08-field: #1a1a22;
--color-tif08-field: oklch(0.23 0.015 285);
--color-tif08-ink: #f0eeff;
--color-tif08-ink: oklch(0.95 0.02 290);
--color-tif08-mut: #b8b6d4;
--color-tif08-mut: oklch(0.77 0.03 290);
--color-tif08-acc: #60a5fa;
--color-tif08-acc: oklch(0.73 0.14 255);
--font-tif08-sans: 'Plus Jakarta Sans', system-ui, sans-serif;
}
.tif-08 {
width: 100%;
}
.tif-08 ::selection {
background: var(--color-tif08-acc);
color: #12121a;
}<link rel="preconnect" href="https://fonts.googleapis.com"> <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin> <link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700&display=swap">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700&display=swap">What changed in the port
Which parts became utilities, which stayed CSS, and why.
- The clear button grew from 22px to
size-11(44px) with a transparent background — same visual weight, a tap target that passes WCAG 2.5.5. :has(input[value=""])is dropped: it never worked, because the attribute does not track what the user typed.:placeholder-showndoes.- The
::-webkit-search-cancel-buttonreset stays a bracket selector — Tailwind has no variant for it and should not invent one.
Here's a working CSS demo from CodeFronts. Use it as-is or adapt to your framework. All classes are scoped under a unique prefix so the code won't collide with your existing styles. MIT licensed.
Demo: Tailwind Search Input With Clear
Source: https://codefronts.com/components/tailwind-css-input-fields/tailwind-search-input-with-clear/
A pill search field with a leading magnifier and a trailing clear button that only exists when there is something to clear. type="reset" does the clearing; has-[input:placeholder-shown]: does the hiding.
## HTML
```html
<div class="tif-08 grid min-h-svh w-full place-items-center bg-tif08-bg px-6 py-14 font-tif08-sans" aria-label="Search input with clear demo">
<form role="search" class="group relative flex w-full max-w-80 items-center gap-1 rounded-full border border-white/10 bg-tif08-field pr-1.5 pl-10 transition-[border-color,box-shadow] duration-200 focus-within:border-tif08-acc focus-within:ring-3 focus-within:ring-tif08-acc/18">
<span class="pointer-events-none absolute left-3.5 grid place-items-center text-tif08-mut transition-colors group-focus-within:text-tif08-acc" aria-hidden="true">
<svg viewBox="0 0 16 16" width="14" height="14"><path fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" d="M11 11l3 3M7 12a5 5 0 1 1 0-10 5 5 0 0 1 0 10z"/></svg>
</span>
<input type="search" name="q" placeholder="Search projects, people, files…" aria-label="Search"
class="min-w-0 flex-1 border-0 bg-transparent py-2.5 text-sm text-tif08-ink outline-none placeholder:text-tif08-mut [&::-webkit-search-cancel-button]:hidden">
<button type="reset" aria-label="Clear search"
class="grid size-11 shrink-0 cursor-pointer place-items-center rounded-full border-0 bg-transparent text-tif08-mut transition-[opacity,background-color,color] duration-150 hover:bg-white/12 hover:text-tif08-ink focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-tif08-acc group-has-[input:placeholder-shown]:pointer-events-none group-has-[input:placeholder-shown]:opacity-0">
<svg viewBox="0 0 12 12" width="10" height="10" aria-hidden="true"><path fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" d="M2 2l8 8M10 2l-8 8"/></svg>
</button>
</form>
</div>
```
## CSS
```css
@import "tailwindcss";
@theme {
--color-tif08-bg: #12121a;
--color-tif08-bg: oklch(0.19 0.015 285);
--color-tif08-field: #1a1a22;
--color-tif08-field: oklch(0.23 0.015 285);
--color-tif08-ink: #f0eeff;
--color-tif08-ink: oklch(0.95 0.02 290);
--color-tif08-mut: #b8b6d4;
--color-tif08-mut: oklch(0.77 0.03 290);
--color-tif08-acc: #60a5fa;
--color-tif08-acc: oklch(0.73 0.14 255);
--font-tif08-sans: 'Plus Jakarta Sans', system-ui, sans-serif;
}
.tif-08 {
width: 100%;
}
.tif-08 ::selection {
background: var(--color-tif08-acc);
color: #12121a;
}
```Here's a working CSS demo from CodeFronts. Use it as-is or adapt to your framework. All classes are scoped under a unique prefix so the code won't collide with your existing styles. MIT licensed.
Demo: Tailwind Search Input With Clear
Source: https://codefronts.com/components/tailwind-css-input-fields/tailwind-search-input-with-clear/
A pill search field with a leading magnifier and a trailing clear button that only exists when there is something to clear. type="reset" does the clearing; has-[input:placeholder-shown]: does the hiding.
## HTML
```html
<div class="tif-08 grid min-h-svh w-full place-items-center bg-tif08-bg px-6 py-14 font-tif08-sans" aria-label="Search input with clear demo">
<form role="search" class="group relative flex w-full max-w-80 items-center gap-1 rounded-full border border-white/10 bg-tif08-field pr-1.5 pl-10 transition-[border-color,box-shadow] duration-200 focus-within:border-tif08-acc focus-within:ring-3 focus-within:ring-tif08-acc/18">
<span class="pointer-events-none absolute left-3.5 grid place-items-center text-tif08-mut transition-colors group-focus-within:text-tif08-acc" aria-hidden="true">
<svg viewBox="0 0 16 16" width="14" height="14"><path fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" d="M11 11l3 3M7 12a5 5 0 1 1 0-10 5 5 0 0 1 0 10z"/></svg>
</span>
<input type="search" name="q" placeholder="Search projects, people, files…" aria-label="Search"
class="min-w-0 flex-1 border-0 bg-transparent py-2.5 text-sm text-tif08-ink outline-none placeholder:text-tif08-mut [&::-webkit-search-cancel-button]:hidden">
<button type="reset" aria-label="Clear search"
class="grid size-11 shrink-0 cursor-pointer place-items-center rounded-full border-0 bg-transparent text-tif08-mut transition-[opacity,background-color,color] duration-150 hover:bg-white/12 hover:text-tif08-ink focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-tif08-acc group-has-[input:placeholder-shown]:pointer-events-none group-has-[input:placeholder-shown]:opacity-0">
<svg viewBox="0 0 12 12" width="10" height="10" aria-hidden="true"><path fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" d="M2 2l8 8M10 2l-8 8"/></svg>
</button>
</form>
</div>
```
## CSS
```css
@import "tailwindcss";
@theme {
--color-tif08-bg: #12121a;
--color-tif08-bg: oklch(0.19 0.015 285);
--color-tif08-field: #1a1a22;
--color-tif08-field: oklch(0.23 0.015 285);
--color-tif08-ink: #f0eeff;
--color-tif08-ink: oklch(0.95 0.02 290);
--color-tif08-mut: #b8b6d4;
--color-tif08-mut: oklch(0.77 0.03 290);
--color-tif08-acc: #60a5fa;
--color-tif08-acc: oklch(0.73 0.14 255);
--font-tif08-sans: 'Plus Jakarta Sans', system-ui, sans-serif;
}
.tif-08 {
width: 100%;
}
.tif-08 ::selection {
background: var(--color-tif08-acc);
color: #12121a;
}
```How this works
Empty is a state the form can read. The whole toggle is one variant pair on the button, with no script and no class swapping:
class="transition-opacity
group-has-[input:placeholder-shown]:pointer-events-none
group-has-[input:placeholder-shown]:opacity-0"Reset needs its own form. type="reset" clears every field in the enclosing form, which is exactly right when the search field is the form — as here — and exactly wrong when it is one field among many.
Make it yours
- Icons: both SVGs are
stroke="currentColor", so they inherit from the utilities around them. - Shape:
rounded-fullon the shell.rounded-xlgives a boxier search bar. - Halo:
focus-within:ring-3 focus-within:ring-tif08-acc/18. - Reveal:
duration-150on the clear button's opacity transition.
Gotchas — read before shipping
- The
placeholdermust be non-empty or:placeholder-shownnever flips and the button never appears. type="reset"resets the whole form — wrap the field in its own<form>, as here, or use a click handler.- A hidden-but-focusable button is a focus-order bug:
pointer-events-noneplusopacity-0is the minimum, andhiddenwould be better if you can accept no transition.
Browser support
| Chrome | Safari | Firefox | Edge |
|---|---|---|---|
| 111+ | 16.4+ | 128+ | 111+ |
:has() is Baseline as of Firefox 121; without it the clear button is always visible and still works.