Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save umidjons/b223e80db8cf17a3986636b0bc575b7d to your computer and use it in GitHub Desktop.
Save umidjons/b223e80db8cf17a3986636b0bc575b7d to your computer and use it in GitHub Desktop.
Floating label (placeholder) on input focus

Floating label (placeholder) on input focus

Working fiddle

Sample code:

<style>
.wrapper { position: relative; }

.control:focus ~ .floating-label,
.control:not(:focus):valid ~ .floating-label{
  top: 6px;
  left: 5px;
  font-size: 11px;
  opacity: 0.6;
}

.control {
  font-size: 14px;
  width: 200px;
  height: 45px;
}

.floating-label {
  position: absolute;
  pointer-events: none;
  left: 20px;
  top: 14px;
  transition: 0.3s ease all;
}
</style>

<div class="wrapper">
  <input type="text" class="control" required/>
  <span class="floating-label">First Name</span>
</div>
<div class="wrapper">
  <input type="text" class="control" required/>
  <span class="floating-label">Last Name</span>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment