How to Create a Contact Form in HTML & CSS
Don’t start from scratch. Use this free generator to build a beautiful, responsive contact form for your website. Customize the colors and text, then copy the code.
🎨 Design Your Form
Live Preview:
ResponsiveContact Us
Important Note
HTML forms need a backend to actually send emails. The code above sets the action to a placeholder #. To make it work without coding a backend, check the guide below about services like Formspree.
Why Build a Custom Contact Form?
Learning how to create a contact form in HTML and CSS is a fundamental skill for web developers. While you can use plugins or drag-and-drop builders, a custom coded form gives you complete control over the design, performance, and user experience. It loads faster and fits perfectly into your brand’s aesthetic.
1. The HTML Structure
The foundation of any contact form is the HTML <form> element. Inside this wrapper, we place input fields for data collection. The most common inputs are:
<input type="text">: For single-line text like names or subjects.<input type="email">: Validates that the user entered a proper email format.<textarea>: For multi-line text, perfect for the actual message body.<button>: To submit the data.
2. Styling with CSS
Raw HTML forms look plain and outdated. By applying CSS, we transform them into professional interfaces. Key styling techniques include:
- Box Model: Adding
paddingandmarginto breathe space into the form elements. - Borders & Radius: Using
border-radiusto soften harsh corners. - Focus States: changing the
border-colorwhen a user clicks into an input (input:focus) improves accessibility and user experience. - Responsiveness: Using
max-width: 100%ensures your form looks great on mobile phones.
3. Making the Form Work (The Backend)
This is where many beginners get stuck. HTML can collect data, but it cannot send emails on its own. The action attribute in the form tag tells the browser where to send the data.
If you don’t want to write server-side code (like PHP or Node.js), you can use a “Form Backend as a Service.” Popular free options include:
- Formspree: You simply set your form action to
https://formspree.io/f/your-form-id. - Netlify Forms: If you host on Netlify, just add the
netlifyattribute to your form tag. - Web3Forms: Allows sending emails via an API without registration for simple use cases.
The generator above provides the complete frontend code. To go live, simply replace the action="#" in the generated code with the URL provided by your chosen backend service.
https://quickcalculators.in/how-to-add-whatsapp-chat-button-to-website/