HTML Forms

Learn how to create and use forms in HTML

HTML Forms

HTML forms are used to collect user input. The

element is used to create an HTML form for user input.

Basic Form Structure

<form action="submit.php" method="post">
  <label for="name">Name:label>
  <input type="text" id="name" name="name" required>
  <input type="submit" value="Submit">
form>

Form Elements

Here are some common form elements:

  • <input>: Used for various input types (text, password, radio, checkbox, etc.)
  • <textarea>: Used for multiline text input
  • <select>: Used to create a drop-down list
  • <button>: Defines a clickable button

Form Attributes

Important form attributes include:

  • action: Specifies where to send the form-data when a form is submitted
  • method: Specifies the HTTP method to use when sending form-data (GET or POST)
  • name: Specifies the name of a form

Example: Complex Form

<form action="submit.php" method="post">
<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>

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

<input type="submit" value="Submit">
</form>