Utilities✨ Premium

Form Adapt

First name / Last name / Email form that puts First and Last name side by side once its column reaches 280 px, and stacks them below — no media query.

CSS@containerForm

Updated

This effect is part of Effect.Labs — 840 vanilla effects, some free, some premium. Utilities has 43 effects, including 3 free. Explore the category →

3 usage examples

Atelier Fendrille — the same sign-up in the page and in a pop-up — Form Adapt example 1

① Atelier Fendrille — the same sign-up in the page and in a pop-up

WhenA bookbinding workshop page: under the title, the “Book my seat” form fills a 300 px column with first and last name side by side. On the right, a 190 px “Waiting list” pop-up reuses exactly the same form: there the fields stack.
WhyOne form to maintain for the page and the pop-up; each takes the shape that suits its spot, with no extra class.
SettingsTwo roots, 300 px and 176 px. Light colours set by the scene: root #fffaf2, white fields with a #dccfbb border, #7c2d12 button. Button labels changed in the HTML.
Gabarix — preview in a form builder being resized — Form Adapt example 2

② Gabarix — preview in a form builder being resized

WhenA form-building tool: the field list on the left, the newsletter form preview on the right in a frame with a handle. Dragging the handle moves the preview from stacked to two columns beyond 280 px; a counter shows the width.
WhyThe form's author sees at once how it will look in a narrow column and in a wide one, before embedding it.
SettingsRoot in a 214 to 372 px frame (root 196 to 354 px); handle and counter belong to the scene (mouse or arrow keys); for the capture the frame widens on its own. Button gradient #0e8376 → #085e56.
Thaldec joinery — “Request a call back” form when the chat opens — Form Adapt example 3

③ Thaldec joinery — “Request a call back” form when the chat opens

WhenA craftsman's footer: the address on the left, the call-back form in the middle. Clicking “Chat” opens the chat window inside the footer: the form column goes from about 340 to 170 px and the fields stack by themselves.
WhyThe form stays readable and complete even when another element takes its room; nothing to plan in the chat's code.
SettingsRoot in a 1fr grid column; #1d1610 background with an amber border, #b06105 → #8c4107 button, padding: 12px. The “Chat” button is the scene's; for the capture it is replayed every 1.4 s.

How it works

The .fx-0753-root element is the queried container (container: cqf-form / inline-size) and holds a real <form class="cqf-form" method="post">. First and last name sit together in .cqf-row; Email and the .cqf-submit button follow. Each field is a <label class="cqf-group"> wrapping its .cqf-label text and its <input class="cqf-input">: the label is tied to the field without an id, so two forms on one page never clash.

Below 280 px of root width, .cqf-row is a column: the fields stack 10 px apart. The @container cqf-form (min-width: 280px) rule turns the row horizontal and gives both fields flex: 1, so they share the width. The column you place the form in is what counts: full-page it uses two columns, in a pop-up or a narrow sidebar it stacks, with the same code.

No JavaScript: submission is the browser's own. Add your form service's action attribute to the <form>. Fields already carry name and autocomplete (given-name, family-name, email) and Email is required: the browser stops a submission with no address.

Accessibility

  • Tied labels: each <label> wraps its field; the screen reader announces “First name, edit text” and clicking the label puts the cursor in the field.
  • Autofill: autocomplete lets the browser and password managers offer name and address, handy with a finger on mobile.
  • Visible focus: #a78bfa border and 2 px halo on fields, 2 px outline on the button. Tab order follows the visual order in both layouts.
  • Contrast: labels in 60 % white on #0a0a0f (about 7:1), placeholder text in 48 % white on the field background (4.9:1), typed text in white.
  • Motion: no animation; switching layouts is instant, so there is nothing to cut under prefers-reduced-motion.

Browser compatibility

Container queries (Chrome 105, Firefox 110, Safari 16). Measured in Chromium 151, Firefox 153 and WebKit 26.5: fields stacked at 170, 250 and 279 px, first and last name side by side at 281, 350, 500 and 800 px; the root fills the whole area (800/800 px); Tab goes First name, Last name, Email, Send; 0 errors.

Chrome 105+✓ Full (measured)
Firefox 110+✓ Full (measured)
Safari 16+✓ Full (measured in WebKit)
Edge 105+✓ Full
Mobile iOS 16+✓ Full
Android Chrome 105+✓ Full

Without container queries, fields stay stacked at every width: the form remains complete and usable.

The code

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

index.html — structure
<div class="fx-0753-root">
  <form class="cqf-form" method="post">
    <div class="cqf-row">
      <label class="cqf-group"><span class="cqf-label">…</span><input class="cqf-input" …></label>
      <label class="cqf-group"><span class="cqf-label">…</span><input class="cqf-input" …></label>
    </div>
    <label class="cqf-group"><span class="cqf-label">…</span><input class="cqf-input" type="email" …></label>
    <button type="submit" class="cqf-submit">…</button>
  </form>
</div>

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

Customize

Options passed to the API or data-* attributes:

Option / propertyDefaultEffect
Breakpoint (CSS — @container cqf-form (min-width: 280px)) 280 px Raise it if your labels are long or your fields wider.
Submission (HTML — action and method on the <form>) method="post", no action (posts to the page itself) Point it to your form service or wire your own script.
Fields (HTML — .cqf-group) First name, Last name, Email (required) Any <label class="cqf-group"> placed in .cqf-row joins the same line beyond the breakpoint; outside the row it stays full width.
Button colour (CSS — .cqf-submit) Gradient #8453f5 → #7631ec Replace the background.
Field colours (CSS — .cqf-input) Background rgba(255,255,255,.06), border rgba(255,255,255,.1), focus #a78bfa On a light background, make the fields white with a warm grey border, as in the Fendrille example.
Background (CSS — .fx-0753-root) #0a0a0f with 16 px corners Set background: transparent to take your section's colour.

FAQ

Not on its own. It is a real <form> with no action: add your service's address (or your own sending code). The effect only handles the layout.
The form looks at its root's width. In a 260 px column it stays stacked whatever the screen size; that is intended, and it is what makes it reusable in a pop-up or a sidebar.
Yes: place a third <label class="cqf-group"> inside .cqf-row and raise the breakpoint (around 420 px) so each field keeps a comfortable width.