A warm, two-column contact form for Bootstrap 6 with floating labels and validation that runs almost entirely in CSS. The left column explains response times and how the email address is used; the right column holds the form with name, email, subject, optional company, message and a consent checkbox. It suits company websites, SaaS support pages and agency portfolios.
How it works
The <form class="cfv-form"> carries Bootstrap 6's data-bs-validate attribute together with novalidate. Bootstrap then styles fields with the :user-invalid pseudo-class: a field turns red and its .invalid-feedback sibling appears only after the visitor has interacted with it, never on first load. A submit attempt marks every field as touched, so pressing "Send message" on an empty form highlights all required fields at once. Each field uses .form-floating with the <label> before the control, as Bootstrap 6 expects.
The script adds three small things. It updates .cfv-count-n while typing in .cfv-message (limit 600, highlighted with .is-near past 90%). On submit it mirrors validity into aria-invalid, writes a summary such as "Please fix 3 fields above." into the .cfv-status live region and focuses the first invalid control. When everything is valid, the button shows a .spinner-border, then the form resets and the .cfv-success alert (alert theme-success) appears with the sender's first name and email.
Customization
--cfv-accentand--cfv-accent-darkon.cfv-root: change the orange of the button, checkbox, focus ring and icons; the scoped--bs-primary-*overrides follow them.--cfv-sand,--cfv-lineand--cfv-inkon.cfv-root: adjust the diagonal background, borders and heading color.minlengthandmaxlengthon#cfv-message: change the message limits; the counter readsmaxlengthautomatically.<option>elements in#cfv-subject: list your own topics.- Use
data-bs-validate="valid"instead ofdata-bs-validateto also show a green valid state. - Replace the
setTimeoutin the submit handler withfetch('/api/contact', { method: 'POST', body: new FormData(form) }).
Use cases
- Business websites: a contact form with floating labels and validation that needs no JavaScript
- Support and inquiry pages: a character counter guides the length of the message
- Privacy-conscious sites: a consent checkbox is required before sending
- Landing pages: a simulated send shows a success alert once the form is valid
Accessibility
Every control has a real <label>, and each error message is linked through aria-describedby. Invalid fields get aria-invalid="true", the summary line is a role="status" region and the character counter is aria-live="polite". After a successful send, focus moves to the success alert; its close button returns focus to the name field. Focus rings use the accent color at a readable contrast.
Bootstrap 6 notes
Bootstrap 5 needed JavaScript to add .was-validated; Bootstrap 6 replaces that with data-bs-validate and :user-invalid. .form-select is gone, so the subject uses .form-control on a <select>. Checkboxes are a plain .check inside .form-field, alerts use alert theme-success, and btn-primary becomes btn-solid theme-primary. Built on Bootstrap 6.0.0-alpha.1, so APIs may still change.