D DevBrainBox

HTML5 Forms

HTML

What is an HTML form?

An HTML form is used to collect user input.

It can collect:

. Text

. Emails

. Passwords

. Choices (radio, checkbox)

. Files And more

A form sends this data to a server (or handles it with JavaScript) to process.

<form action="/submit" method="post">
  <!-- form elements go here -->
</form>
AttributeMeaning
actionThe URL where form data will be sent.
methodHTTP method (get or post).

Common Form Elements

TagWhat it does
<input>Takes various kinds of input (text, email, password, etc).
<textarea>For multi-line text.
<select>Dropdown list.
<option>Options inside <select>
<button>Clickable button (submit, reset, etc).
<label>Labels an input for accessibility.
<form action="/submit" method="post">
  <label for="name">Name:</label>
     <input type="text" id="name" name="name" required>

  <br><br>

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

  <br><br>

  <label for="password">Password:</label>
     <input type="password" id="password" name="password" minlength="6" required>

  <br><br>

  <label for="gender">Gender:</label>
     <select id="gender" name="gender">
       <option value="male">Male</option>
       <option value="female">Female</option>
     </select>

  <br><br>

  <label>
     <input type="checkbox" name="subscribe" value="yes">
     Subscribe to newsletter
  </label>

  <br><br>

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

On this page