SYP Start Your Path

HTML Forms — Complete Guide

Forms

Forms collect input from users — names, emails, choices — and send it somewhere for processing.

<form method="POST" action="/submit">
  <label for="name">Name</label>
  <input type="text" id="name" name="name" required>

  <label for="email">Email</label>
  <input type="email" id="email" name="email" required>

  <button type="submit">Submit</button>
</form>

This is the same pattern used by any real signup or contact form — a <label> paired with each field, and a submit button at the end.

Form Attributes

<form method="POST" action="/save-request" autocomplete="off">
  ...
</form>

Form Elements

<label for="course">Course</label>
<select id="course" name="course">
  <option value="html">HTML Basics</option>
  <option value="css-basics">CSS Basics</option>
</select>

<label for="message">Message</label>
<textarea id="message" name="message" rows="4"></textarea>

<fieldset>
  <legend>Preferred contact</legend>
  <input type="radio" id="email-contact" name="contact" value="email">
  <label for="email-contact">Email</label>
  <input type="radio" id="phone-contact" name="contact" value="phone">
  <label for="phone-contact">Phone</label>
</fieldset>

Input Types

<input type="text">      <!-- plain text -->
<input type="email">     <!-- validates email format -->
<input type="password">  <!-- masks characters -->
<input type="number">    <!-- numeric spinner -->
<input type="tel">       <!-- phone number -->
<input type="date">      <!-- date picker -->
<input type="checkbox">  <!-- yes/no toggle -->
<input type="radio">     <!-- pick one of a group -->
<input type="file">      <!-- file upload -->
<input type="hidden">    <!-- invisible, sent with the form anyway -->

Choosing the right type gives users the right keyboard/picker on mobile automatically — e.g. type="tel" shows a number pad.

Input Attributes

<input type="tel" name="phone" placeholder="Mobile / WhatsApp Number"
       pattern="[0-9]{10}" maxlength="10" required>

This exact pattern (type="tel" + pattern + maxlength) is a reliable way to validate a 10-digit phone number on any form.