Search⌘ K

Custom Floating Label Input

Explore how to create custom floating label inputs using CSS to position labels inside input fields that animate and shrink on focus or input. Understand the use of CSS selectors and transitions to mimic material design patterns in form controls without JavaScript.

Problem description

Given an HTML page containing a div with class float-label that wraps an <input type="text" class="floating-input" placeholder=" " id="username" required> and its associated <label for="username">Username</label>, write CSS to:

  • Position the label inside the input field so it appears as ...