Snippets Contact form

Bootstrap 5 Contact Form with Floating Labels

A compact contact form with floating labels, inline validation and a message box, ready to wire to any backend.

Bootstrap 5 No jQuery Apr 2019 2.5K views

<section class="wdw-stage">
  <div class="container" style="max-width: 960px;">
    <div class="wdw-card overflow-hidden" id="contact-wrap">
      <div class="row g-0">
        <aside class="col-lg-5 wdw-aurora p-4 p-md-5 d-flex flex-column justify-content-between gap-4">
          <div>
            <span class="wdw-eyebrow text-white-50">Get in touch</span>
            <h2 class="wdw-heading h3 mb-2 text-white">Contact us</h2>
            <p class="mb-0 text-white-50">Tell us about your project for a custom quote. We reply within one business day.</p>
          </div>
          <ul class="list-unstyled d-grid gap-3 mb-0">
            <li class="d-flex align-items-center gap-3"><span class="wdw-icon flex-shrink-0" aria-hidden="true"><svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="5" width="18" height="14" rx="2"/><path d="m3 7 9 6 9-6"/></svg></span><span><span class="d-block small text-white-50">Email</span>[email protected]</span></li>
            <li class="d-flex align-items-center gap-3"><span class="wdw-icon flex-shrink-0" aria-hidden="true"><svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round"><path d="M5 4h4l2 5-2.5 1.5a11 11 0 0 0 5 5L15 13l5 2v4a2 2 0 0 1-2 2A16 16 0 0 1 3 6a2 2 0 0 1 2-2z"/></svg></span><span><span class="d-block small text-white-50">Phone</span>+1 (555) 013-2040</span></li>
            <li class="d-flex align-items-center gap-3"><span class="wdw-icon flex-shrink-0" aria-hidden="true"><svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="9"/><path d="M12 7v5l3 2"/></svg></span><span><span class="d-block small text-white-50">Hours</span>Mon to Fri, 9:00 to 17:30</span></li>
          </ul>
        </aside>
        <form class="col-lg-7 p-4 p-md-5" id="contact" novalidate>
          <fieldset class="mb-4">
            <legend class="form-label fw-semibold fs-6">What is this about?</legend>
            <div class="d-flex flex-wrap gap-2">
              <input type="radio" class="btn-check" name="topic" id="tp-1" value="Project" checked><label class="btn btn-outline-primary rounded-pill" for="tp-1">Project</label>
              <input type="radio" class="btn-check" name="topic" id="tp-2" value="Support"><label class="btn btn-outline-primary rounded-pill" for="tp-2">Support</label>
              <input type="radio" class="btn-check" name="topic" id="tp-3" value="Other"><label class="btn btn-outline-primary rounded-pill" for="tp-3">Other</label>
            </div>
          </fieldset>
          <div class="row g-3">
            <div class="col-sm-6">
              <div class="form-floating"><input type="text" class="form-control" id="ct-name" name="name" placeholder="Your name" autocomplete="name" aria-describedby="ct-name-err" required><label for="ct-name">Your name</label><div class="invalid-feedback" id="ct-name-err" role="alert">Required.</div></div>
            </div>
            <div class="col-sm-6">
              <div class="form-floating"><input type="email" class="form-control" id="ct-email" name="email" placeholder="Email" autocomplete="email" aria-describedby="ct-email-err" required><label for="ct-email">Email address</label><div class="invalid-feedback" id="ct-email-err" role="alert">Valid email needed.</div></div>
            </div>
            <div class="col-sm-6">
              <div class="form-floating"><input type="tel" class="form-control" id="ct-phone" name="phone" placeholder="Phone" autocomplete="tel"><label for="ct-phone">Phone (optional)</label></div>
            </div>
            <div class="col-sm-6">
              <div class="form-floating"><input type="url" class="form-control" id="ct-site" name="website" placeholder="Website" autocomplete="url" aria-describedby="ct-site-err"><label for="ct-site">Website (optional)</label><div class="invalid-feedback" id="ct-site-err" role="alert">Enter a full URL, like https://example.com.</div></div>
            </div>
            <div class="col-12">
              <div class="form-floating"><textarea class="form-control ct-msg" id="ct-msg" name="message" placeholder="Message" aria-describedby="ct-msg-err" required></textarea><label for="ct-msg">Your message</label><div class="invalid-feedback" id="ct-msg-err" role="alert">Please write a short message.</div></div>
            </div>
            <div class="col-12"><button class="btn btn-primary rounded-pill w-100" type="submit">Send message</button></div>
          </div>
          <div class="alert alert-success d-none mt-3 mb-0" id="ct-ok" role="status">Thanks, your message is on its way.</div>
        </form>
      </div>
    </div>
  </div>
</section>

Built on Bootstrap 5.3.8 with plain JavaScript — no jQuery. Supports light and dark mode via data-bs-theme.

Free to use in personal and commercial projects under the MIT license.