Write an HTML program to create a contact form

Description: Create a contact form with name, email, subject and message fields, and a Send button.

Hint:

  • Use textarea for the long message.
  • Mark the important fields with required.

HTML contact form

<form action="contact.php" method="post">
  <p><label for="cname">Name:</label><br>
     <input type="text" id="cname" name="name" required></p>
  <p><label for="cemail">Email:</label><br>
     <input type="email" id="cemail" name="email" required></p>
  <p><label for="subject">Subject:</label><br>
     <input type="text" id="subject" name="subject"></p>
  <p><label for="message">Message:</label><br>
     <textarea id="message" name="message" rows="5" cols="40" required></textarea></p>
  <button type="submit">Send</button>
</form>

Output in the browser:

Output in the browser





How it works

  • <br> puts the field below its label.
  • rows and cols set the size of the textarea.
  • The server file contact.php reads the values and sends the email. A form alone cannot send an email.

Also see our HTML contact form template.


Learn more about the similar topics:
Tutorials
HTML Input Types
HTML Forms
Exercises & Assignments
Write an HTML program to create a registration form
Write an HTML program to create a contact form
Interview Questions & Answers
What are the different new form element types in HTML5?
What is the difference between GET and POST methods in an HTML form?
What is the use of the label tag in HTML?