# Floating Label Input

> A text input whose label floats up when focused or filled. No JavaScript.

- Category: [CSS Form Elements](https://copy-css.com/category/forms)
- Tags: input, label, form, material, focus
- Live preview: https://copy-css.com/snippets/floating-label-input
- License: Free for personal and commercial use. No signup, no attribution required.

## HTML

```html
<label class="field-float">
  <input type="email" placeholder=" ">
  <span>Email address</span>
</label>
```

## CSS

```css
.field-float {
  position: relative;
  display: block;
  width: 240px;
  font-family: system-ui, sans-serif;
}

.field-float input {
  box-sizing: border-box;
  width: 100%;
  padding: 22px 14px 8px;
  border: 1.5px solid #d1d5db;
  border-radius: 10px;
  background: #fff;
  font-size: 16px;
  outline: none;
  transition: border-color 0.2s ease;
}

.field-float span {
  position: absolute;
  top: 50%;
  left: 15px;
  color: #6b7280;
  font-size: 16px;
  pointer-events: none;
  transform: translateY(-50%);
  transition: 0.2s ease;
}

.field-float input:focus {
  border-color: #6366f1;
}

.field-float input:focus + span,
.field-float input:not(:placeholder-shown) + span {
  top: 15px;
  color: #6366f1;
  font-size: 12px;
}
```

## Notes

- This CSS Floating Label Input is 40 lines of pure CSS (0.7 KB) with no JavaScript and no dependencies. It uses transitions and transforms.
- In JSX use `className` instead of `class`. In Tailwind projects put the CSS in the global stylesheet.
