Input Dynamic Label–Placeholder

by adamschwartz

HTML

<div class="input">
  <input type="text" value="" pattern=".*" required>
  <label>Email</label>
</div>
<div class="input">
  <input type="text" value="" pattern=".*" required>
  <label>Name</label>
</div>

CSS

body {
  font-size: 19.3px;
  font-family: Avenir, sans-serif;
  font-weight: normal;
  background: #e2e2e2;
  margin: 1.5em;
}

.input {
  position: relative;
  line-height: 1.5;
  font-size: 1em;
}

.input + .input {
  margin-top: 1em;
}

.input > input {
  outline: none;
}

.input > * {
  box-sizing: border-box;
  font: inherit;
  display: block;
  width: 100%;
  padding: 1.4em .9em .4em;
  border: 0;
  border-radius: .25em;
}

.input > label {
  padding-top: .9em;
  padding-bottom: .9em;
}

.input > label {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  pointer-events: none;
  transform-origin: 0 0;
  opacity: .25;
  transition: transform .3s ease;
}

.input > input:focus + label,
.input > input:valid + label {
  transform: translate3d(.3em, -.2em, 0) scale(.7);
}