FormsPremium

Floating Label V2

An outline-only field with no fill: its label climbs astride the top edge while shrinking to 85%, and the line breaks just behind it. CSS only.

CSSFocusTransform

Updated

This effect is part of Effect.Labs — 846 vanilla effects, some free, some premium. Forms has 21 effects, including 2 free. Explore the category →

3 usage examples

A member's record opened for editing — chess club management software — Floating Label V2 example 1

① A member's record opened for editing — chess club management software

WhenThe record arrives with five fields already filled: their labels are up as soon as it shows, before any field has been touched. The secretary corrects the rating, then completes the only empty field, "Previous club".
WhySix fields on three rows inside a card: with a caption above each, every row would need one more line of text. And since the frame only lights up on focus, the field being corrected is the only indigo one among its neighbours.
SettingsOn the white card: --flv-notch:#fff, --flv-text:#1e2433, --flv-muted:#667085, --flv-border:#cfd4e3, --flv-accent:#4f46e5, --flv-accent-text:#4338ca, --flv-font-size:.86rem, --flv-width:100% in a two-column grid. Root backdrop cancelled. Focus and typing are played by the scene's script.
Emergency contact asked when signing up for a kayak course, on a phone — Floating Label V2 example 2

② Emergency contact asked when signing up for a kayak course, on a phone

WhenThe parent types the number, stops at six digits and taps elsewhere: frame and label turn pink, a message shows under the field. They complete the number and the message goes away.
WhyThe transparent field lets the screen's deep teal through: giving that shade to the notch is all it takes. And flagging the error needs no extra CSS rule, only three variables changed on the root of the faulty field.
Settings--flv-notch:#0e2a33, --flv-accent:#5eead4, --flv-accent-text:#99f6e4, --flv-border turquoise at 32%, field set to type="tel". On error, the scene adds a class that turns --flv-border, --flv-accent and --flv-accent-text pink, sets aria-invalid="true" and shows a role="alert" message linked through aria-describedby. The ten-digit check belongs to the scene, not to the effect.
Filtering half-marathon results by bib number — Floating Label V2 example 3

③ Filtering half-marathon results by bib number

WhenAbove the ranking, a 158 px field. The runner types 2, 7, 4: of the 412 finishers five rows remain, then four, then their own, highlighted.
WhyIn a toolbar, a filter has no room for a caption next to it. Here the instruction stays readable on the edge while the digits appear, and drops back into the field as soon as it is cleared.
Settings--flv-width:158px, --flv-notch:#faf6ee (the page's cream), --flv-accent:#c2410c, --flv-accent-text:#b23a0a, inputmode="numeric". Row filtering and the counter are scene code, wired to the field's input event.

How it works

The field has nothing but a 2 px frame, indigo at 30% at rest, and lets the page show through. The .flv-label text sits inside it, vertically centred. Two situations send it up onto the top edge: the field has focus, or it holds something (:not(:placeholder-shown), made possible by a placeholder=" " reduced to one space). Where the value comes from does not matter: typing, a value attribute already in the HTML or a value written by a script give the same result in Chromium, Firefox and WebKit.

On its way up the label is not rewritten in a smaller font: it keeps its size and goes through transform: scale(.85), in one 0.3 s move together with its shift. At the same moment it gets a background, --flv-notch, and 8 px of padding on each side: that small rectangle hides the frame line behind the text, and it is what draws the notch.

The frame only turns solid indigo while the field has focus. A field that was filled and then left goes back to its faint outline and keeps just its coloured label at the top. In a grid of fields that already hold values, the one being typed in is therefore the only one lit.

A label too long for the field stays on one line and ends with an ellipsis. The .fx-0291-root root supplies the demo backdrop (dark background, 300 px tall) and the box-sizing: in your form, keep it and cancel its backdrop with min-height: 0; padding: 0; background: transparent.

Accessibility

  • A real label: the text that moves up is the content of the <label> wrapping the field. No id to make up, a click on the text puts the caret in the field, and screen readers keep announcing "Email address" once the text has moved.
  • Measured contrast: label at rest #a1a1aa, 7.7:1 on the demo background; raised label #818cf8, 6.6:1 for 13.6 px text. The frame at rest is pale on purpose (1.4:1): the label is what signals the field. For a firmer outline, strengthen --flv-border.
  • Active field: the frame turns solid indigo, with no halo. When the system imposes its colours (Windows high-contrast mode), a 2 px outline takes over; without it, Firefox showed no difference between a filled field and the same field in focus.
  • Input errors: the effect has no error state. The kayak course example shows one way to do it without adding a rule: aria-invalid and aria-describedby on the field, a role="alert" message below it, and three colour variables turned pink on the root.
  • Reduced motion: with prefers-reduced-motion: reduce, the label lands at the top at once and the frame changes colour without a fade.
  • Touch: the field is 46 px tall and its text 16 px. If you lower --flv-font-size below 16 px, Safari on iPhone zooms into the field on tap (a known behaviour of that browser, not measured here).

Browser compatibility

Only two building blocks: :placeholder-shown (Chrome 47, Firefox 51, Safari 9) and CSS variables (Chrome 49, Firefox 31, Safari 9.1), versions taken from @mdn/browser-compat-data. Tried on 04/12/2026 in Chromium 149, Firefox 151 and WebKit 26.5: two copies on one page (the second filled from the keyboard while the first stays still), value present in the HTML, value written by script, touch on a 390 px screen, reduced motion, forced colours. Browser autofill could not be replayed in an automated test.

Chrome 49+✓ Full (measured in Chromium 149)
Firefox 51+✓ Full (measured in Firefox 151)
Safari 9.1+✓ Full (measured in WebKit 26.5)
Edge 79+✓ Full (Chromium engine)
iOS Safari 9.3+✓ Not checked on a real device
Android Chrome 49+✓ Full (Chromium engine)

A pre-2017 browser that does not know :placeholder-shown lets the label drop back over the value as soon as the field loses focus: the effect is not meant for it. No script is involved, so nothing changes when JavaScript is blocked.

The code

HTML structure to paste into your page (the CSS + JS come with your purchase):

index.html — structure
<div class="fx-0291-root">
  <label class="flv-field">
    <input class="flv-input" type="email" name="email" autocomplete="email" placeholder=" ">
    <span class="flv-label">Email address</span>
  </label>
</div>

One-time payment, no subscription — the code is yours forever

Customize

Options passed to the API or data-* attributes:

Option / propertyDefaultEffect
Width (CSS — --flv-width) 280px A length, or 100% to match the column. The field never exceeds its parent (max-width: 100%).
Notch background (CSS — --flv-notch) #0a0a0f The flat colour of whatever sits behind the field. Over a photo or a gradient the small rectangle would show: the effect needs a solid colour.
Frame (CSS — --flv-border, --flv-accent) indigo at 30% · #6366f1 Outline at rest, outline while in focus.
Texts (CSS — --flv-text, --flv-muted, --flv-accent-text) #fff · #a1a1aa · #818cf8 Typed value, label inside the field, raised label. On a light background darken all three (see the chess club example) and aim for 4.5:1 on the raised label, which is small.
Text size (CSS — --flv-font-size) 1rem Sets the field and the label together; once raised, the label is always 85% of that size.
Shrink and duration (CSS — scale(.85), transition) .85 · 0.3 s In the raised-label rule and on .flv-input / .flv-label. Below .75 the label gets hard to read; beyond 0.4 s it lags behind typing.
Kind of field (HTML) type="email" name="email" autocomplete="email" Text, phone, number: change these attributes, not the placeholder=" ", without which the label can no longer tell whether the field is empty.

FAQ

Floating Label is a filled field: tinted background, a label that changes font size, a frame that stays indigo as long as a value is there, a 3 px halo on focus. Here the field is a transparent outline, the label shrinks through a transform and the frame only lights up while typing. Same mechanism, different drawing: pick V2 on a flat colour, or in a dense form where the active field must stand out at once.
That is the notch: it has its own colour, #0a0a0f by default, and cannot guess your page's. Give --flv-notch the right value on the field or on a parent (#fff for a white card).
Add a paragraph under the root, give it an id and link it to the field with aria-describedby. When the value is rejected, set aria-invalid="true", show the message (role="alert" gets it announced) and turn --flv-border, --flv-accent and --flv-accent-text to your error colour on the root. That check remains your code: the effect validates nothing.