HTML Tutorial

Forms

Input fields, buttons, and collecting user data

What is a Form?

Forms are used to collect user input. The collected data is most often sent to a server for processing (like a Login or a Contact form).
html
<form action="/submit-data" method="POST">
  <label for="name">Name:</label>
  <input type="text" id="name" name="user_name">
  <button type="submit">Send</button>
</form>

Input Types

The <input> tag is extremely versatile. The type attribute changes how it looks and behaves.
TypeDescription
textStandard single-line text
passwordHides characters as you type
emailValidates that the input is a real email
numberOnly allows numeric digits
checkboxMultiple choice selections
radioSingle choice from a group
dateA native date picker

Textareas and Selects

  1. <textarea>: For multi-line text (like a comment box).
  2. <select>: For a dropdown list of options.

Labels

Wait! Always connect your <label> to your <input> using the for and id attributes. This is critical for accessibility and makes it easier for users to click on small checkboxes or radio buttons.

Summary

TermDescription
formThe wrapper for all inputs
actionThe URL where the data is sent
methodGET (visible in URL) or POST (hidden/secure)
requiredPrevents the form from being sent if empty
placeholderGrey text that disappears when the user types
Best ForUser interaction and data collection
Logic"User-to-Server communication"
SafetyUse POST for sensitive data like passwords
ModernClient-side validation is built directly into HTML5
StandardEvery input should have a corresponding label
IdentityForms are the "Engine" of the interactive web