Components & UI Animation — Reference

Floating Label

The Floating Label is a CSS animation component that an input label that smoothly floats upward when the field receives focus or contains text. A polished form pattern that saves space and provides clear context for each input. It ships as self-contained HTML and CSS with no external dependencies, making it drop-in ready for any modern web project regardless of framework or build system.

labelinputfloatfocusform

When to use the Floating Label

Performance characteristics

How it compares

Unlike equivalent JavaScript implementations, the Floating Label does not require any runtime library — there is nothing to install, bundle, or load asynchronously.

Compared to animated GIFs or video embeds, this CSS component is resolution-independent, theme-able via CSS custom properties, and weighs a fraction of the equivalent media file.

Source code

CSS

css
.field { position: relative; width: 280px; }
  .field input { width: 100%; padding: 16px 12px 8px; font-size: 16px; border: 2px solid #3f3f46; border-radius: 8px; background: #18181b; color: #fff; outline: none; transition: border-color 0.2s, box-shadow 0.2s; }
  .field input:focus { border-color: #3b82f6; box-shadow: 0 0 0 3px #3b82f633; }
  .field label { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: #71717a; pointer-events: none; transition: all 0.2s ease; }
  .field input:focus + label, .field input:not(:placeholder-shown) + label { top: 8px; transform: translateY(0); font-size: 11px; color: #3b82f6; }
  body { margin: 0; min-height: 100vh; display: flex; align-items: center; justify-content: center; background: #0f0f0f; }

HTML

html
<div class="field"><input type="text" placeholder=" " id="i"/><label for="i">Email</label></div>

Full source

html
<!DOCTYPE html>
<html><head><style>
  .field { position: relative; width: 280px; }
  .field input { width: 100%; padding: 16px 12px 8px; font-size: 16px; border: 2px solid #3f3f46; border-radius: 8px; background: #18181b; color: #fff; outline: none; transition: border-color 0.2s, box-shadow 0.2s; }
  .field input:focus { border-color: #3b82f6; box-shadow: 0 0 0 3px #3b82f633; }
  .field label { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: #71717a; pointer-events: none; transition: all 0.2s ease; }
  .field input:focus + label, .field input:not(:placeholder-shown) + label { top: 8px; transform: translateY(0); font-size: 11px; color: #3b82f6; }
  body { margin: 0; min-height: 100vh; display: flex; align-items: center; justify-content: center; background: #0f0f0f; }
</style></head><body>
  <div class="field"><input type="text" placeholder=" " id="i"/><label for="i">Email</label></div>
</body></html>

Frequently asked questions

How do I add the Floating Label to my project?

Copy the full source code from the code block on this page. Paste the <style> block into your stylesheet (or a <style> tag in your HTML head) and the HTML markup into your template. No npm install or build step is required — the animation is self-contained. To customize colors, speed, or size, use Grepped's workspace at grepped.dev/animations/components-ui/floating-label.

Is the Floating Label free to use?

Yes. All Grepped preset animations are free to use in personal and commercial projects. You may copy, modify, and redistribute the code without attribution. The only limitation is that you may not resell the presets themselves as part of a competing animation library.

Does the Floating Label work on mobile browsers?

Yes. The Floating Label uses standard CSS animations and transforms that are supported in all modern mobile browsers — Chrome for Android, Safari on iOS 9+, Samsung Internet, and Firefox for Android. Where JavaScript is used for interactivity (e.g. cursor effects), it falls back gracefully on touch devices.

Can I customize the Floating Label's colors, speed, or size?

Yes. Open the live customization workspace at grepped.dev/animations/components-ui/floating-label to adjust the animation with real-time sliders, color pickers, and toggles — no code required. For deeper changes, the source code uses CSS custom properties (variables) so you can edit them directly in your stylesheet.

Want to customize this animation or generate a new one from a text prompt?

Open in Workspace — it's free