Skip to content

Floating Label Form Fields

Dark Bootstrap 6 project request form with floating label inputs, selects and a textarea, CSS-only validation, a character counter and simulated submit.

Also known as: floating label form, project request form, agency contact form, dark contact form, floating input labels

Bootstrap 6 Inputs Responsive Dark #dark #floating-label #form #input #validation

Floating Label Form Fields live demo

Open in new tab

Bootstrap 6 code (HTML, CSS, JS)

A dark project-request form for agency and studio sites. It shows Bootstrap 6 floating labels on text inputs, selects and a textarea, with CSS-only validation, a character counter and a simulated submit. The intro column with perks makes it a ready-made contact section.

How it works

The root .flf-root uses data-bs-theme="dark" and splits into .flf-intro and the .flf-form card. Each field is a .form-field.flf-field that holds a .form-floating wrapper, with the <label> placed before its control as Bootstrap 6 requires, plus an .invalid-feedback message. Text inputs need a placeholder because the label floats via :placeholder-shown. Selects always show the floated label.

The form has data-bs-validate and novalidate, so Bootstrap colors fields red through :user-invalid only after the visitor edits them or tries to submit. Bootstrap does not show feedback that sits after a .form-floating wrapper. A small rule in style.css therefore shows .invalid-feedback when its .flf-field contains an invalid control. The email field starts with a server-style .is-invalid state, so the error design is visible right away. script.js removes that class once the visitor edits the field.

The script also updates the .flf-count counter (it turns amber near maxlength) and keeps aria-invalid in sync. On submit it focuses the first :invalid field. If the form is valid, it shows a spinner, resets the form and reveals the .flf-success alert. Label animations start only after load, via the .flf-animate class.

Customization

  • --flf-violet and --flf-pink on .flf-root: change the accent and the submit button gradient. The root also maps Bootstrap's --bs-primary-*, --bs-focus-ring-color and --bs-control-checked-bg to the accent.
  • --flf-message-height on .flf-root: sets the textarea height through --bs-form-floating-height. Avoid the rows attribute with floating labels.
  • data-bs-validate="valid" on .flf-form: also shows green success styling on valid fields.
  • Remove is-invalid and aria-invalid from #flf-email and clear its value for a clean first state.
  • Replace the setTimeout in the submit handler with fetch() to your endpoint. Keep the form.reset() call for the success path.
  • .flf-grid switches to two columns at 576px. Add .flf-span to a field to make it full width.

Use cases

  • Agency and studio websites: a project request form with an intro column of perks beside it
  • Contact sections: floating label inputs, selects and a textarea keep a compact, modern form
  • Briefing and inquiry forms: a character counter on the message field guides how much detail visitors write
  • Lead capture pages: validation errors appear only after editing, then a success alert confirms the send

Accessibility

Every control has a real label (required ones end in *, explained in a note linked with aria-describedby). Error messages are linked with aria-describedby, and aria-invalid is set on blur and on submit. Focus moves to the first invalid field. The success alert uses role="status". Focus rings use the violet accent on a dark background with strong contrast.

Bootstrap 6 notes

form-select is gone: selects use form-control. The floating <label> now comes before the input, and the mb-3 wrapper becomes .form-field. form-check markup becomes a single input.check with a .form-field-content column. Validation uses data-bs-validate instead of the Bootstrap 5 was-validated JavaScript. Spinners use spinner-sm. Built on Bootstrap 6.0.0-alpha.1, so APIs may still change. Icons come from Bootstrap Icons.

Floating Label Form Fields at a glance

Framework
Bootstrap 6
Code
HTML, CSS, JavaScript
JavaScript
Vanilla JavaScript, no jQuery
Dependencies
Bootstrap 6, Bootstrap Icons
Layout
Responsive, works on mobile, dark design
Category
Inputs
License
Free for personal and commercial use

Questions about this template

Can I use the Floating Label Form Fields code for free?

Yes. You can copy or download the code and use it in personal and commercial projects, including client work. No sign-up is needed. Reselling it as part of a component library or template collection is not allowed; see the license.

How do I add it to my website?

Load Bootstrap 6 and Bootstrap Icons from a CDN (the links are under Requirements). Paste the HTML where the component should appear, add the CSS to your stylesheet and load the JavaScript before the closing </body> tag. Download HTML gives you a complete page with everything already linked.

Does it need jQuery or a JavaScript framework?

No. The script is plain vanilla JavaScript, so it works without jQuery, React or Vue. You can still use the markup inside those frameworks.

Does it work on mobile?

Yes. The layout adapts to small screens. Use the Mobile and Tablet buttons above the live demo to check it at phone and tablet width.

Requirements

Add these to your page (already included in the download):

  • <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@6.0.0-alpha.1/dist/css/bootstrap.min.css">
  • <script type="module" src="https://cdn.jsdelivr.net/npm/bootstrap@6.0.0-alpha.1/dist/js/bootstrap.bundle.min.js"></script>
  • <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">

Built for Bootstrap 6.0.0-alpha.1. Bootstrap 6 ships as an ES module, so its script and this component's JavaScript load with type="module". Alpha releases can still change before the stable version.

Floating Label Form Fields – Bootstrap 6 inputs component screenshot
Floating Label Form Fields · Bootstrap 6 Inputs

More Inputs

Password Strength Meter – Bootstrap 5 inputs preview

Password Strength Meter

Bootstrap 5 password input with show/hide toggle, four-step strength meter, live requirements checklist and confirmation match check.

Inputs with Icons and Add-ons – Tailwind CSS inputs preview

Inputs with Icons and Add-ons

Tailwind CSS input group examples with leading icons, text prefixes and suffixes, a currency select, password toggle, clear button and helper text.

OTP Code Input – Bootstrap 6 inputs preview

OTP Code Input

Dark Bootstrap 6 OtpInput verification card with 6 digit slots, paste support, auto-advance, auto-verify on complete, error state and a resend countdown.

Password Input with Strength Meter – Bootstrap 6 inputs preview

Password Input with Strength Meter

Bootstrap 6 password field with show/hide toggle, the Strength meter, a live requirement checklist, confirm match, Caps Lock hint and a password generator.

Input Groups with Icons and Buttons – Bootstrap 6 inputs preview

Input Groups with Icons and Buttons

Bootstrap 6 input group examples in a settings card: icon and text prefixes, suffixes, a currency menu, stepper, copy button and validated coupon field.

Tag Input with Removable Chips – Tailwind CSS inputs preview

Tag Input with Removable Chips

Tailwind CSS tag input that turns typed words into removable chips, with Enter and comma support, paste splitting, a tag limit and suggestions.