CSS Input with Icon

An email field with a leading mail icon that tints on focus and a green check that appears once the value is valid.

  • icon
  • email
  • leading icon
  • valid
  • checkmark
  • input
HTML
<label class="icon-field">
  <span class="icon-field-label">Work email</span>
  <span class="icon-field-box">
    <svg viewBox="0 0 24 24" aria-hidden="true"><rect x="3" y="5" width="18" height="14" rx="2"/><path d="m3 7 9 6 9-6"/></svg>
    <input type="email" name="email" autocomplete="email" placeholder="you@company.com" value="sam@studio.dev">
  </span>
</label>
CSS
.icon-field {
  display: grid;
  gap: 6px;
  width: 260px;
  font-family: system-ui, sans-serif;
}

.icon-field-label {
  color: #3b0764;
  font-size: 13px;
  font-weight: 600;
}

.icon-field-box {
  position: relative;
  display: block;
}

.icon-field svg {
  position: absolute;
  top: 50%;
  left: 12px;
  width: 18px;
  height: 18px;
  fill: none;
  stroke: #a1a1aa;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  transform: translateY(-50%);
  pointer-events: none;
  transition: stroke 0.2s ease;
}

.icon-field input {
  box-sizing: border-box;
  width: 100%;
  padding: 11px 38px 11px 40px;
  border: 1.5px solid #ddd6fe;
  border-radius: 10px;
  background: #fff no-repeat right 12px center / 16px;
  color: #18181b;
  font: 15px system-ui, sans-serif;
  outline: none;
}

.icon-field input:focus {
  border-color: #7c3aed;
  box-shadow: 0 0 0 4px rgba(124, 58, 237, 0.15);
}

.icon-field-box:focus-within svg {
  stroke: #7c3aed;
}

.icon-field input:valid:not(:placeholder-shown) {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2316a34a' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 12.5 10 17 19 7'/%3E%3C/svg%3E");
}

About this CSS Input with Icon

This CSS Input with Icon is 58 lines of pure CSS (1.2 KB) with no JavaScript and no dependencies. It uses transitions, transforms, box shadows and CSS Grid. It works in current versions of Chrome, Edge, Safari and Firefox. It works in any stack: plain HTML, React, Vue, Svelte, Astro, WordPress or Webflow.

CSS features used

Customize it

The colors in this snippet. Search and replace them to match your brand:

  • #3b0764
  • #a1a1aa
  • #ddd6fe
  • #fff
  • #18181b
  • #7c3aed

How to use this input with icon

  1. Copy the HTML and paste it where you want the element to appear.
  2. Copy the CSS into your stylesheet, or inside a <style> tag.
  3. Keep the .icon-field class name, or rename it in both places. Then tweak colors, sizes and timing to match your design.
  4. Using React or Next.js? Change class to className in the HTML. The CSS works as is, including in Tailwind projects (put it in your global stylesheet).

Building with an AI tool?

“Copy for AI” copies a short prompt for Cursor, Claude Code, Lovable, Bolt or v0. Your AI tool opens the Markdown version of this snippet and reads the HTML, CSS and setup notes there. If your tool can't open links, with the code instead. More ways to use copy CSS with AI.

Feedback