CSS Contact Form

A tidy contact form with name and email side by side on wide screens, a message box and a send button.

  • contact
  • form
  • message
  • textarea
  • responsive
  • grid
HTML
<form class="contact-form">
  <label>Name<input type="text" name="name" autocomplete="name" required></label>
  <label>Email<input type="email" name="email" autocomplete="email" required></label>
  <label class="contact-form-wide">Message<textarea name="message" rows="3" required></textarea></label>
  <button type="submit">Send message</button>
</form>
CSS
.contact-form {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 10px;
  width: 100%;
  max-width: 340px;
  padding: 16px;
  box-sizing: border-box;
  border-radius: 16px;
  background: #fff;
  font-family: system-ui, sans-serif;
}

.contact-form label {
  display: grid;
  gap: 4px;
  color: #334155;
  font-size: 12px;
  font-weight: 600;
}

.contact-form-wide,
.contact-form button {
  grid-column: 1 / -1;
}

.contact-form input,
.contact-form textarea {
  box-sizing: border-box;
  width: 100%;
  padding: 8px 10px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  background: #f8fafc;
  color: #0f172a;
  font: 14px system-ui, sans-serif;
  resize: vertical;
}

.contact-form input:focus-visible,
.contact-form textarea:focus-visible {
  border-color: #0f172a;
  outline: 2px solid #0f172a;
  outline-offset: -1px;
  background: #fff;
}

.contact-form button {
  padding: 10px;
  border: 0;
  border-radius: 8px;
  background: #0f172a;
  color: #fff;
  font: 600 14px system-ui, sans-serif;
  cursor: pointer;
}

.contact-form button:hover {
  background: #334155;
}

.contact-form button:focus-visible {
  outline: 2px solid #0f172a;
  outline-offset: 2px;
}

About this CSS Contact Form

This CSS Contact Form is 65 lines of pure CSS (1.2 KB) with no JavaScript and no dependencies. It uses CSS Grid and keyboard focus styles. It works in current versions of Chrome, Edge, Safari and Firefox. It works in any stack: plain HTML, React, Vue, Svelte, Astro, WordPress or Webflow.

CSS features used

Customize it

The colors in this snippet. Search and replace them to match your brand:

  • #fff
  • #334155
  • #cbd5e1
  • #f8fafc
  • #0f172a

How to use this contact form

  1. Copy the HTML and paste it where you want the element to appear.
  2. Copy the CSS into your stylesheet, or inside a <style> tag.
  3. Keep the .contact-form class name, or rename it in both places. Then tweak colors, sizes and timing to match your design.
  4. Using React or Next.js? Change class to className in the HTML. The CSS works as is, including in Tailwind projects (put it in your global stylesheet).

Building with an AI tool?

“Copy for AI” copies a short prompt for Cursor, Claude Code, Lovable, Bolt or v0. Your AI tool opens the Markdown version of this snippet and reads the HTML, CSS and setup notes there. If your tool can't open links, with the code instead. More ways to use copy CSS with AI.

Feedback