Back to HTML
Lesson 3 of 3

HTML Forms

Create interactive forms for user input

HTML Forms

Forms allow users to input data that can be sent to a server for processing.

Basic Form Structure

<form action="/submit" method="POST">
  <label for="name">Name:</label>
  <input type="text" id="name" name="name">
  
  <label for="email">Email:</label>
  <input type="email" id="email" name="email">
  
  <button type="submit">Submit</button>
</form>

Input Types

  • text - Single line text
  • email - Email with validation
  • password - Hidden input
  • number - Numeric input
  • date - Date picker
  • checkbox - Multiple selections
  • radio - Single selection

Form Validation

<input required>         <!-- Field is required -->
<input minlength="3">    <!-- Minimum characters -->
<input pattern="[A-Z]+"> <!-- Regex pattern -->