Search⌘ K

Floating Label Input with Validation Message

Explore how to implement a floating label input with a validation message using only CSS. Learn to use CSS variables, positioning, and transitions to create accessible form controls that display labels above inputs on focus or when filled and show error messages when inputs are invalid. This lesson helps you master pattern-based CSS techniques for better form UI design.

Problem description

Given an HTML page containing a <div class="validate-wrapper"> that wraps an <input type="email" id="email" class="validate-input" placeholder=" " required> and a <label for="email" data-error="Please enter a valid email address">Email</label>, write CSS to:

  • Define CSS variables on .validate-wrapper: --primary-color, --error-color, and --transition-duration.

  • Set ...