Tailwind CSS contact form: a responsive template that actually sends
A clean, accessible Tailwind CSS contact form template with focus states, error styles and a success message, wired to a form backend so submissions reach your inbox. Copy, paste, done.

Most Tailwind form templates look great and do nothing: the <form> has no action, or posts to #. This one is ready to receive real messages. It is responsive, accessible and uses only standard Tailwind utility classes (written for Tailwind v4; notes for v3 below).
The template
<form id="contact" action="https://api.formiz.app/submit" method="POST"
class="mx-auto grid max-w-xl gap-5 rounded-2xl bg-white p-6 shadow-sm ring-1 ring-black/5 sm:p-8">
<input type="hidden" name="access_key" value="YOUR_ACCESS_KEY">
<input type="hidden" name="subject" value="New message from the website">
<input type="checkbox" name="_honey" class="hidden" tabindex="-1" autocomplete="off">
<div>
<h2 class="text-2xl font-bold tracking-tight text-gray-900">Get in touch</h2>
<p class="mt-1 text-sm text-gray-600">We reply within one business day.</p>
</div>
<div class="grid gap-5 sm:grid-cols-2">
<label class="grid gap-1.5 text-sm font-medium text-gray-900">
Name
<input name="name" autocomplete="name" required
class="rounded-lg border border-gray-300 px-3 py-2.5 text-base font-normal text-gray-900 shadow-sm
placeholder:text-gray-400 focus:border-gray-900 focus:outline-none focus:ring-2 focus:ring-gray-900/10
user-invalid:border-red-500">
</label>
<label class="grid gap-1.5 text-sm font-medium text-gray-900">
Email
<input name="email" type="email" autocomplete="email" required
class="rounded-lg border border-gray-300 px-3 py-2.5 text-base font-normal text-gray-900 shadow-sm
focus:border-gray-900 focus:outline-none focus:ring-2 focus:ring-gray-900/10
user-invalid:border-red-500">
</label>
</div>
<label class="grid gap-1.5 text-sm font-medium text-gray-900">
Message
<textarea name="message" rows="5" required
class="rounded-lg border border-gray-300 px-3 py-2.5 text-base font-normal text-gray-900 shadow-sm
focus:border-gray-900 focus:outline-none focus:ring-2 focus:ring-gray-900/10
user-invalid:border-red-500"></textarea>
</label>
<div class="flex flex-wrap items-center gap-4">
<button type="submit"
class="rounded-lg bg-gray-900 px-5 py-2.5 text-sm font-semibold text-white shadow-sm transition
hover:bg-gray-700 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2
focus-visible:outline-gray-900 disabled:cursor-not-allowed disabled:opacity-60">
Send message
</button>
<p id="contact-status" role="status" class="text-sm text-gray-600"></p>
</div>
</form>Replace YOUR_ACCESS_KEY with a free key from Formiz and add your email under Channels → Email. That is enough for a working form: without JavaScript, visitors see a thank-you page after sending.
Inline success message
<script>
const form = document.getElementById('contact');
const status = document.getElementById('contact-status');
form.addEventListener('submit', async (e) => {
e.preventDefault();
const btn = form.querySelector('button');
btn.disabled = true;
status.textContent = 'Sending…';
try {
const res = await fetch(form.action, { method: 'POST', body: new FormData(form) });
const data = await res.json();
if (!data.success) throw new Error(data.message);
form.reset();
status.textContent = '✓ Thanks! Your message has been sent.';
status.className = 'text-sm font-medium text-green-700';
} catch (err) {
status.textContent = err.message || 'Something went wrong.';
status.className = 'text-sm font-medium text-red-600';
} finally {
btn.disabled = false;
}
});
</script>Design notes
user-invalid:variant. Shows red borders only after the visitor interacts with a field, never on page load. It is built into Tailwind v4. On v3, remove it or add a custom variant withaddVariant('user-invalid', '&:user-invalid'). Background: HTML5 form validation.text-baseon inputs prevents iOS Safari from zooming in when a field is focused (it zooms when font size is below 16px).- Labels wrap inputs, so clicking the label focuses the field and screen readers announce it. See accessible contact forms.
sm:grid-cols-2puts name and email side by side on larger screens and stacks them on phones.- Honeypot uses Tailwind's
hiddenclass (display: none), which keeps it away from people and screen readers alike.
Dark mode
Add dark: variants if your site supports it:
<form class="... bg-white dark:bg-gray-900 dark:ring-white/10">
<input class="... dark:border-gray-700 dark:bg-gray-800 dark:text-white">In React, Vue or Svelte
The classes work unchanged in JSX (class → className) and Vue/Svelte templates. For component logic, see React, Vue or SvelteKit.
Get your form working in five minutes
Create a free Formiz key, add it to your form and receive submissions by email and Telegram. No server, no SMTP, no card.


