JSFiddle - React, Tailwind, and code Playground

by Mukesh Yadav

HTML

<div class="floatingLabel">
  <input type="text" class="inputText" required/>
  <span class="floating-label">Your email address</span>
</div>

CSS

.floatingLabel input:focus ~ .floating-label,
.floatingLabel input:not(:focus):valid ~ .floating-label{
  top: 8px;
  bottom: 10px;
  left: 20px;
  font-size: 11px;
  opacity: 1;
}

.floatingLabel .inputText {
  font-size: 14px;
  width: 200px;
  height: 35px;
}

.floatingLabel .floating-label {
  position: absolute;
  pointer-events: none;
  left: 20px;
  top: 18px;
  transition: 0.2s ease all;
}