Bootstrap 5 Contact Form Examples
Four modern contact form styles: floating labels, split panel with contact details, topic chips and a dark card, each with built-in validation.
<section class="cf-section wdw-stage">
<div class="container">
<div class="text-center mx-auto mb-4" style="max-width:32rem">
<span class="wdw-eyebrow mb-2">Contact forms</span>
<h2 class="wdw-heading h3 mb-0">Four ways to say hello</h2>
</div>
<div class="row g-3 g-lg-4">
<div class="col-md-6">
<div class="wdw-card cf-card h-100">
<form class="cf-form needs-validation d-flex flex-column h-100 p-3 p-lg-4" novalidate>
<p class="wdw-eyebrow mb-1">Style 1 · Simple</p>
<h3 class="h5 wdw-heading mb-1">Send us a message</h3>
<p class="small text-body-secondary mb-3">Questions or feedback. We reply within a day.</p>
<div class="mb-3"><label for="cf1-email" class="form-label small fw-semibold">Email</label><input type="email" class="form-control" id="cf1-email" placeholder="[email protected]" required><div class="invalid-feedback">Please enter a valid email.</div></div>
<div class="mb-3"><label for="cf1-msg" class="form-label small fw-semibold">Message</label><textarea class="form-control" id="cf1-msg" rows="6" placeholder="How can we help?" required></textarea><div class="invalid-feedback">Tell us a little more.</div></div>
<button type="submit" class="btn btn-primary w-100 rounded-pill mt-auto">Send message</button>
<div class="cf-ok alert alert-success d-none mt-3 mb-0 rounded-3 py-2 small" role="status">Thanks! Your message is on its way.</div>
</form>
</div>
</div>
<div class="col-md-6">
<div class="wdw-card cf-card h-100 overflow-hidden">
<div class="d-flex flex-column h-100">
<div class="wdw-aurora p-3 p-lg-4">
<p class="wdw-eyebrow cf-onaurora mb-1">Style 2 · Contact details</p>
<h3 class="h5 fw-bold mb-3">Let's talk</h3>
<ul class="cf-contact list-unstyled small mb-0 d-flex flex-column flex-sm-row flex-sm-wrap gap-2 column-gap-3">
<li class="d-flex gap-2 align-items-center"><svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" class="flex-shrink-0"><rect x="3" y="5" width="18" height="14" rx="2"/><path d="m3 7 9 6 9-6"/></svg>[email protected]</li>
<li class="d-flex gap-2 align-items-center"><svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" class="flex-shrink-0"><path d="M22 16.9v3a2 2 0 0 1-2.2 2 19.8 19.8 0 0 1-8.6-3.1 19.5 19.5 0 0 1-6-6A19.8 19.8 0 0 1 2.1 4.2 2 2 0 0 1 4.1 2h3a2 2 0 0 1 2 1.7c.1 1 .4 1.9.7 2.8a2 2 0 0 1-.5 2.1L8 9.9a16 16 0 0 0 6 6l1.3-1.3a2 2 0 0 1 2.1-.4c.9.3 1.8.6 2.8.7a2 2 0 0 1 1.7 2z"/></svg>+1 (555) 014 2290</li>
<li class="d-flex gap-2 align-items-center"><svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" class="flex-shrink-0"><path d="M12 21s7-6.2 7-11.5A7 7 0 0 0 5 9.5C5 14.8 12 21 12 21z"/><circle cx="12" cy="9.5" r="2.5"/></svg>21 Market St, Portland</li>
</ul>
</div>
<form class="cf-form needs-validation d-flex flex-column flex-grow-1 p-3 p-lg-4" novalidate>
<div class="mb-3"><label for="cf2-name" class="form-label small fw-semibold">Name</label><input type="text" class="form-control" id="cf2-name" placeholder="Jane Cooper" required><div class="invalid-feedback">Your name is required.</div></div>
<div class="mb-3"><label for="cf2-email" class="form-label small fw-semibold">Email</label><input type="email" class="form-control" id="cf2-email" placeholder="[email protected]" required><div class="invalid-feedback">Please enter a valid email.</div></div>
<div class="mb-3"><label for="cf2-msg" class="form-label small fw-semibold">Message</label><textarea class="form-control" id="cf2-msg" rows="3" placeholder="How can we help?" required></textarea><div class="invalid-feedback">Please write a message.</div></div>
<button type="submit" class="btn btn-primary w-100 rounded-pill mt-auto">Send</button>
<div class="cf-ok alert alert-success d-none mt-3 mb-0 rounded-3 py-2 small" role="status">Message sent. Thank you!</div>
</form>
</div>
</div>
</div>
<div class="col-md-6">
<div class="wdw-card cf-card h-100">
<form class="cf-form needs-validation d-flex flex-column h-100 p-3 p-lg-4" novalidate>
<p class="wdw-eyebrow mb-1">Style 3 · Topic chips</p>
<h3 class="h5 wdw-heading mb-3">What's on your mind?</h3>
<fieldset class="mb-3">
<legend class="visually-hidden">Topic</legend>
<div class="d-flex flex-wrap gap-2">
<input type="radio" class="btn-check" name="cf3-topic" id="cf3-a" checked><label class="btn btn-outline-secondary cf-chip rounded-pill btn-sm px-3" for="cf3-a">General</label>
<input type="radio" class="btn-check" name="cf3-topic" id="cf3-b"><label class="btn btn-outline-secondary cf-chip rounded-pill btn-sm px-3" for="cf3-b">Support</label>
<input type="radio" class="btn-check" name="cf3-topic" id="cf3-c"><label class="btn btn-outline-secondary cf-chip rounded-pill btn-sm px-3" for="cf3-c">Sales</label>
<input type="radio" class="btn-check" name="cf3-topic" id="cf3-d"><label class="btn btn-outline-secondary cf-chip rounded-pill btn-sm px-3" for="cf3-d">Press</label>
</div>
</fieldset>
<div class="mb-3"><label for="cf3-email" class="form-label small fw-semibold">Email</label><input type="email" class="form-control" id="cf3-email" placeholder="[email protected]" required><div class="invalid-feedback">Please enter a valid email.</div></div>
<div class="mb-3"><label for="cf3-msg" class="form-label small fw-semibold">Message</label><textarea class="form-control" id="cf3-msg" rows="4" placeholder="Write your message..." required></textarea><div class="invalid-feedback">Please write a message.</div></div>
<div class="mt-auto d-flex flex-column flex-sm-row align-items-sm-center justify-content-between gap-2">
<span class="small text-body-secondary order-2 order-sm-1">Average reply: 4 hours</span>
<button type="submit" class="btn btn-primary rounded-pill px-4 order-1 order-sm-2">Send message</button>
</div>
<div class="cf-ok alert alert-success d-none mt-3 mb-0 rounded-3 py-2 small" role="status">Sent! We'll be in touch.</div>
</form>
</div>
</div>
<div class="col-md-6">
<div class="wdw-card cf-card h-100">
<form class="cf-form needs-validation d-flex flex-column h-100 p-3 p-lg-4" novalidate>
<p class="wdw-eyebrow mb-1">Style 4 · Support ticket</p>
<h3 class="h5 wdw-heading mb-1">Open a support ticket</h3>
<p class="small text-body-secondary mb-3">Tell us what's broken and we'll investigate.</p>
<div class="mb-3">
<label for="cf4-cat" class="form-label small fw-semibold">Category</label>
<select class="form-select" id="cf4-cat" required>
<option value="" selected disabled>Choose a category</option>
<option>Billing</option><option>Bug report</option><option>Account access</option><option>Feature request</option>
</select>
<div class="invalid-feedback">Please choose a category.</div>
</div>
<div class="mb-3"><label for="cf4-msg" class="form-label small fw-semibold">Describe the issue</label><textarea class="form-control" id="cf4-msg" rows="3" placeholder="What happened?" required></textarea><div class="invalid-feedback">Please describe the issue.</div></div>
<div class="mb-3">
<label for="cf4-file" class="form-label small fw-semibold">Attachment <span class="fw-normal text-body-secondary">(optional)</span></label>
<input type="file" class="form-control" id="cf4-file">
</div>
<button type="submit" class="btn btn-primary w-100 rounded-pill mt-auto">Submit ticket</button>
<div class="cf-ok alert alert-success d-none mt-3 mb-0 rounded-3 py-2 small" role="status">Ticket created. We'll email you shortly.</div>
</form>
</div>
</div>
</div>
</div>
</section>
/* Web Designer Wall library style — shared base for every Bootstrap 5 snippet.
Indigo accent, Plus Jakarta Sans, soft cards, pill buttons. Works in light and dark. */
@import url("https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700;800&display=swap");
:root,
[data-bs-theme="light"] {
--wdw-font: "Plus Jakarta Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
--bs-body-font-family: var(--wdw-font);
--bs-primary: #4f46e5;
--bs-primary-rgb: 79, 70, 229;
--bs-primary-text-emphasis: #3730a3;
--bs-primary-bg-subtle: #eef2ff;
--bs-primary-border-subtle: #c7d2fe;
--bs-link-color: #4f46e5;
--bs-link-color-rgb: 79, 70, 229;
--bs-link-hover-color: #4338ca;
--bs-link-hover-color-rgb: 67, 56, 202;
--bs-focus-ring-color: rgba(79, 70, 229, 0.25);
--bs-border-radius: 0.75rem;
--bs-border-radius-lg: 1rem;
--bs-border-radius-xl: 1.25rem;
--wdw-radius-card: 1.25rem;
--wdw-shadow: 0 1px 2px rgba(16, 24, 40, 0.05), 0 16px 40px -16px rgba(16, 24, 40, 0.22);
--wdw-shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06), 0 4px 12px -4px rgba(16, 24, 40, 0.12);
--wdw-stage: #f5f6fb;
}
[data-bs-theme="dark"] {
--bs-primary: #818cf8;
--bs-primary-rgb: 129, 140, 248;
--bs-primary-text-emphasis: #c7d2fe;
--bs-primary-bg-subtle: rgba(129, 140, 248, 0.14);
--bs-primary-border-subtle: rgba(129, 140, 248, 0.35);
--bs-link-color: #a5b4fc;
--bs-link-color-rgb: 165, 180, 252;
--bs-link-hover-color: #c7d2fe;
--bs-link-hover-color-rgb: 199, 210, 254;
--bs-focus-ring-color: rgba(129, 140, 248, 0.35);
--wdw-shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 16px 40px -16px rgba(0, 0, 0, 0.7);
--wdw-shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4), 0 4px 12px -4px rgba(0, 0, 0, 0.5);
--wdw-stage: #0f1117;
}
body { font-family: var(--wdw-font); -webkit-font-smoothing: antialiased; }
/* Bootstrap compiles its blue into these components; point them at the accent. */
.btn-primary {
--bs-btn-bg: var(--bs-primary); --bs-btn-border-color: var(--bs-primary);
--bs-btn-hover-bg: #4338ca; --bs-btn-hover-border-color: #4338ca;
--bs-btn-active-bg: #3730a3; --bs-btn-active-border-color: #3730a3;
--bs-btn-disabled-bg: var(--bs-primary); --bs-btn-disabled-border-color: var(--bs-primary);
--bs-btn-focus-shadow-rgb: var(--bs-primary-rgb);
}
[data-bs-theme="dark"] .btn-primary { --bs-btn-color: #0f1117; --bs-btn-hover-bg: #a5b4fc; --bs-btn-hover-border-color: #a5b4fc; --bs-btn-hover-color: #0f1117; --bs-btn-active-color: #0f1117; }
.btn-outline-primary {
--bs-btn-color: var(--bs-primary); --bs-btn-border-color: var(--bs-primary);
--bs-btn-hover-bg: var(--bs-primary); --bs-btn-hover-border-color: var(--bs-primary);
--bs-btn-active-bg: var(--bs-primary); --bs-btn-active-border-color: var(--bs-primary);
--bs-btn-focus-shadow-rgb: var(--bs-primary-rgb);
}
.btn { --bs-btn-font-weight: 600; min-height: 44px; display: inline-flex; align-items: center; justify-content: center; gap: .5rem; }
.btn-sm { min-height: 36px; }
.form-control, .form-select { min-height: 44px; border-radius: .75rem; }
.form-control:focus, .form-select:focus, .form-check-input:focus { border-color: rgba(var(--bs-primary-rgb), .6); box-shadow: 0 0 0 .25rem var(--bs-focus-ring-color); }
.form-check-input:checked { background-color: var(--bs-primary); border-color: var(--bs-primary); }
.nav-pills { --bs-nav-pills-link-active-bg: var(--bs-primary); }
.nav { --bs-nav-link-color: var(--bs-secondary-color); --bs-nav-link-hover-color: var(--bs-emphasis-color); }
.pagination { --bs-pagination-active-bg: var(--bs-primary); --bs-pagination-active-border-color: var(--bs-primary); --bs-pagination-color: var(--bs-body-color); --bs-pagination-focus-box-shadow: 0 0 0 .25rem var(--bs-focus-ring-color); }
.progress, .progress-stacked { --bs-progress-bar-bg: var(--bs-primary); }
.list-group { --bs-list-group-active-bg: var(--bs-primary); --bs-list-group-active-border-color: var(--bs-primary); }
.dropdown-menu { --bs-dropdown-link-active-bg: var(--bs-primary); border-radius: .875rem; box-shadow: var(--wdw-shadow-sm); }
.accordion { --bs-accordion-active-bg: var(--bs-primary-bg-subtle); --bs-accordion-active-color: var(--bs-primary-text-emphasis); --bs-accordion-btn-focus-box-shadow: 0 0 0 .25rem var(--bs-focus-ring-color); }
.badge { font-weight: 600; }
/* Library building blocks — use these instead of re-inventing them per snippet. */
.wdw-stage { min-height: 100vh; display: flex; align-items: center; background: var(--wdw-stage); padding-block: 3rem; }
.wdw-card { background: var(--bs-body-bg); border: 1px solid var(--bs-border-color-translucent); border-radius: var(--wdw-radius-card); box-shadow: var(--wdw-shadow); }
.wdw-card-sm { background: var(--bs-body-bg); border: 1px solid var(--bs-border-color-translucent); border-radius: 1rem; box-shadow: var(--wdw-shadow-sm); }
.wdw-aurora { position: relative; color: #fff; background: radial-gradient(60% 55% at 100% 0, #818cf8 0, transparent 70%), radial-gradient(65% 60% at 0 100%, #ec4899 0, transparent 65%), #1e1b4b; }
.wdw-eyebrow { display: inline-block; font-size: .75rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--bs-primary); }
.wdw-heading { font-weight: 800; letter-spacing: -.02em; color: var(--bs-emphasis-color); }
.wdw-muted { color: var(--bs-secondary-color); }
.wdw-icon { width: 2.75rem; height: 2.75rem; flex: none; display: inline-flex; align-items: center; justify-content: center; border-radius: .875rem; background: var(--bs-primary-bg-subtle); color: var(--bs-primary); }
/* Component */
.cf-card { transition: transform .2s ease; }
.cf-card:hover { transform: translateY(-2px); }
.cf-onaurora { color: rgba(255, 255, 255, .8); }
.cf-section .form-control, .cf-section .form-select { background-color: var(--bs-body-bg); }
.cf-section textarea.form-control { min-height: 0; }
.cf-chip { --bs-btn-color: var(--bs-body-color); --bs-btn-border-color: var(--bs-border-color); --bs-btn-hover-bg: transparent; --bs-btn-hover-color: var(--bs-body-color); --bs-btn-hover-border-color: var(--bs-primary); min-height: 36px; }
.btn-check:checked + .cf-chip { background: var(--bs-primary); border-color: var(--bs-primary); color: #fff; }
[data-bs-theme="dark"] .btn-check:checked + .cf-chip { color: #0f1117; }
.btn-check:focus-visible + .btn { box-shadow: 0 0 0 .25rem var(--bs-focus-ring-color); }
@media (prefers-reduced-motion: reduce) { .cf-card { transition: none; } .cf-card:hover { transform: none; } }
function initContactForms() {
document.querySelectorAll('.cf-form').forEach(function (form) {
form.addEventListener('submit', function (e) {
e.preventDefault();
var ok = form.querySelector('.cf-ok');
form.classList.add('was-validated');
if (!form.checkValidity()) {
if (ok) ok.classList.add('d-none');
return;
}
if (ok) ok.classList.remove('d-none');
form.reset();
form.classList.remove('was-validated');
});
});
}
initContactForms();
Built on Bootstrap 5.3.8 with plain JavaScript — no jQuery. Supports light and dark mode via data-bs-theme.