Form Snippets — Free HTML CSS JS Copy-Paste Form Components

116 form components · Floating labels, OTP, Range, Password strength, Multi-step · Exports to React, Vue, Angular & Tailwind

Share & Support

What's included

Features

13 form components covering input, selection, upload, and payment patterns
Floating label: pure CSS :placeholder-shown + ~ sibling combinator — zero JS
OTP input: auto-advance focus, paste-to-fill 6-digit split, backspace navigation
Password strength: 4 regex tests (length/upper/digit/symbol), 0–4 score, coloured bar
Credit card: XXXX XXXX XXXX XXXX auto-format, Visa/MC/Amex type detection, card preview
File dropzone: dragover/drop events + click browse + extension colour badge map
Tag input: Enter/comma add, duplicate prevention, backspace-last-remove, × chip button
Multi-step: done/active/pending dot states, boundary guards, step count display
Segmented control: offsetLeft/offsetWidth sliding pill via CSS left+width transition

About this tool

Form Snippets — Free, 13 Production-Ready Form Components for Sign-Up, Checkout, and Settings

Forms are where users take meaningful action — sign up, purchase, configure settings, upload files, and enter sensitive data. Poorly designed form components create friction, increase drop-off, and make products feel unpolished. Well-crafted form components reduce cognitive load, prevent errors, and build trust. This collection covers every form component a modern web product needs.

Every snippet is plain HTML, CSS, and vanilla JavaScript with no external dependencies. Each component demonstrates a real production technique that you can study, adapt, and ship immediately.

Floating Label Input achieves the animated label-to-placeholder transition with zero JavaScript. The CSS :placeholder-shown pseudo-class detects whether the input is empty. The ~ sibling combinator targets the label. When the field is empty, the label sits inside the input as placeholder text. When the user types, :placeholder-shown becomes false and a CSS transition floats the label up to the top edge. No JS event listener needed.

OTP / PIN Input auto-advances focus as each digit is entered, handles paste-to-fill (splitting a 6-digit code across all inputs at once), and handles backspace-to-previous navigation. This is the exact interaction pattern users expect from two-factor authentication flows.

Password Strength Meter runs four regex tests — minimum length (8+ chars), uppercase letter presence, digit presence, and symbol presence — and scores 0–4. The result is a coloured bar (red → orange → yellow → green) with a text label. Each rule check is a separate test so users get targeted feedback about which requirement they have not yet met.

Credit Card Input auto-formats the number as XXXX XXXX XXXX XXXX using a replace regex that inserts spaces every 4 digits. It detects the card type (Visa, Mastercard, Amex, Discover) from the first digit and updates a type indicator. The preview below the inputs shows the formatted number, cardholder name, and expiry in a card-face layout.

Multi-Step Form uses three step dots that transition between done (filled with checkmark), active (accent ring), and pending (grey) states. Navigation guards prevent advancing if the current step's required fields are empty. A progress label shows "Step 2 of 3." Each step's content panel shows and hides via display toggling.

File Dropzone handles drag-and-drop events (dragover, drop) and click-to-browse. Dropped files get name, size, and extension-based colour badge entries in a file list. A simple size formatter shows bytes as KB, MB, or GB. The dropzone border changes colour while a file is being dragged over it.

Tag Input lets users type a tag and press Enter or comma to add it to a list. Duplicate tags are rejected silently. The backspace key removes the last tag when the input is empty. Each tag has a × remove button. Tags render as chips in a wrapping flex row.

Segmented Control shows a sliding pill indicator that moves to the selected segment via CSS left and width transitions. moveIndicator() reads btn.offsetLeft and btn.offsetWidth at click time — actual pixel values — and sets the pill's position. Works for any label length.

Range Slider, Toggle Switch, Star Rating, Colour Picker, and Search Box complete the collection with the remaining essential form patterns, all with live preview and full export support.

Real-world uses

Common Use Cases

Sign-up, registration, and onboarding flows
Floating label inputs for a clean sign-up form. OTP input for email or phone number verification. Password strength meter for account creation. Multi-step form for onboarding wizards that break a long form into manageable steps.
Payment, checkout, and document upload
Credit card input with auto-formatting and real-time type detection for checkout forms. File dropzone for document and image upload flows. Multi-step form for shipping → billing → confirm purchase flows with per-step validation.
App settings, preferences, and configuration panels
Toggle switch for enabling and disabling feature flags, email notifications, and privacy settings. Segmented control for switching between view modes (list/grid), time ranges (day/week/month), or editor themes. Range slider for audio volume, image brightness, and threshold controls.
Search interfaces and filter tag management
Search box with :focus-within ring glow for site-wide search bars and command inputs. Tag input for managing search filters, skill tags, category labels, and any UI where users add and remove items from a dynamic list.
Study pure CSS form interaction techniques
The floating label is a masterclass in CSS-only interaction — no JavaScript at all. Study how :placeholder-shown, :focus, and the ~ sibling combinator combine to detect state and animate the label. Each snippet in this collection teaches a different real technique used in production.
Survey, feedback, and data collection forms
Star rating for product reviews, NPS scores, and post-purchase feedback. Segmented control for multiple-choice survey questions. Colour picker for theme and preference customisation. All components integrate directly with standard HTML form submission or JavaScript fetch.

Got questions?

Frequently Asked Questions

No. All 13 components are plain HTML, CSS, and vanilla JavaScript. The floating label uses zero JavaScript — it is pure CSS with :placeholder-shown and the sibling combinator. Every other component uses only inline script or a simple function call. Copy any snippet directly into an HTML file, a PHP template, a Jinja template, or any server-rendered page and it works immediately without an npm install.

Standard text inputs: input.value. OTP input: collect all digit inputs with [...document.querySelectorAll(".otp-input")].map(i => i.value).join(""). Tag input: [...document.querySelectorAll(".tag-chip")].map(t => t.dataset.value || t.textContent.replace("×","").trim()). Credit card number: strip spaces from the formatted value with input.value.replace(/s/g,""). Range slider: input.value returns the current number. Star rating: the data-selected attribute on the container.

All inputs use semantic HTML elements — input, label, button, select — with correct for/id associations between label and input. All are keyboard-focusable by default. For production accessibility: add aria-required="true" to required fields, aria-invalid="true" on fields with validation errors, aria-describedby pointing to inline error messages, and role="switch" with aria-checked on toggle switches. The OTP input manages focus programmatically and announces digit count for screen readers.

Click "JSX" on any snippet to download a React component. In React: replace oninput with onChange, replace onkeydown with onKeyDown, and manage all values in useState. The floating label needs no state — it still works via CSS :placeholder-shown in JSX. For the OTP input, manage an array of 6 values in useState and derive focus management in a useEffect. For the credit card, format the number value in the onChange handler before setting state.