# 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.

- Category: [CSS Form Elements](https://copy-css.com/category/forms)
- Tags: icon, email, leading icon, valid, checkmark, input
- Live preview: https://copy-css.com/snippets/input-with-icon
- License: Free for personal and commercial use. No signup, no attribution required.

## HTML

```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

```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");
}
```

## Notes

- 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.
- In JSX use `className` instead of `class`. In Tailwind projects put the CSS in the global stylesheet.
