Back to CSS Search Boxes Floating Label Pure CSS
Share
HTML
<form class="csb-float" role="search">
  <input id="csb-float-i" type="search" name="q" placeholder=" " />
  <label for="csb-float-i">Search anything</label>
</form>
CSS
.csb-float {
  position: relative; display: inline-block;
}
.csb-float input {
  width: 240px; padding: 18px 14px 8px;
  background: #1a1a28;
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 8px;
  color: #f0eeff; font: 500 14px/1 system-ui, sans-serif;
  outline: none;
  transition: border-color 0.2s;
}
.csb-float input:focus { border-color: #7c6cff; }
.csb-float label {
  position: absolute;
  left: 14px; top: 50%;
  transform: translateY(-50%);
  color: #7a7899; font: 500 14px/1 system-ui, sans-serif;
  pointer-events: none;
  transition: top 0.2s, font-size 0.2s, color 0.2s;
}
.csb-float input:focus + label,
.csb-float input:not(:placeholder-shown) + label {
  top: 12px;
  font-size: 10.5px;
  color: #a78bfa;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}