Skip to content
IndexRequest a UIAboutContact

Text Input

A text field whose label floats above the value when focused or filled.

Open alone ↗

AI prompt

PROMPT: PASTE INTO YOUR AI CODING TOOL
Create a text input with a floating label using only HTML and CSS. Structure: a wrapper containing an input with placeholder=" " followed by a label element linked by for/id. The field is 56px tall with a 1px border, 12px radius and 16px font size. The label starts vertically centred inside the field; when the input is focused or not showing its placeholder (:not(:placeholder-shown)) or autofilled, the label moves up to the top edge, scales to 0.78 and changes to the accent colour while focused, over 160ms ease-out. Focus shows a 2px accent border. Add helper text below ("We never share your email"). Include a second field that is disabled. Ensure font-size 16px, associate the helper text with aria-describedby, and drop the movement under prefers-reduced-motion.

About this pattern

Definition

A single-line text field with a label that sits inside the field as a placeholder and moves above the text once the field is focused or has a value. Helper text sits underneath.

Purpose & UX principles

  • Saves vertical space while keeping the label visible after the user starts typing, which a plain placeholder cannot do.
  • The label is a real label element tied to the input, so tapping it focuses the field and screen readers announce it.
  • Never rely on placeholder text as the only label.

Interaction states

  • Empty, focused (accent border), filled (label stays floated), disabled (muted), with helper text.
  • Browser autofill is detected with :autofill so the label floats and does not overlap the filled value.

Motion specification

  • Label: translateY and scale, 160ms ease-out.
  • Border colour and ring: 160ms.
  • Reduced motion: label moves instantly.

Responsive behaviour

  • Field height 56px, full width of its container, font size at least 16px so mobile browsers do not zoom on focus.
  • Labels longer than the field truncate with an ellipsis when floated.

Code

HTML
<div class="form">
  <div class="field"><input id="e" type="email" placeholder=" " aria-describedby="h" autocomplete="email"><label for="e">Email address</label><p id="h" class="help">We never share your email.</p></div>
  <div class="field"><input id="n" type="text" placeholder=" " autocomplete="name"><label for="n">Full name</label></div>
  <div class="field"><input id="d" type="text" placeholder=" " disabled value="Locked value"><label for="d">Disabled</label></div>
</div>

Related patterns

Search Input

↗
Search InputInputs & Forms

Validation States

↗
Validation StatesInputs & Forms

Toggle Switch

↗
Toggle SwitchInputs & Forms