HTML Forms

Subject: html

📄 HTML Forms Overview

HTML Forms are used to collect user input. They allow users to enter data that can be submitted to a server for processing or validated on the client side.


🔧 1. Basic Form Syntax

An HTML form is defined using the <form> tag. It acts as a container for input fields and interactive controls.

  • action: URL where form data is sent when submitted
  • method: HTTP method used for submission (GET or POST)

⚙️ 2. Common <form> Attributes

AttributeDescription
actionURL to which the form data is sent
methodHTTP method: get or post
autocompleteEnables/disables autofill
targetSpecifies where to display the response
novalidateDisables built-in form validation
enctypeType of content used when sending data (for files)

🧱 3. Common Form Elements

ElementPurpose
<input>Single-line input for text, password, etc.
<textarea>Multi-line text input
<select> + <option>Drop-down menu
<button>Trigger form actions like submit/reset
<label>Associates text with an input field

Example:


🔤 4. HTML Input Types

The <input> tag supports various type values for different purposes:

TypeDescription
textSingle-line text input
passwordHidden characters for passwords
emailValidates email input
numberNumeric input with optional range
checkboxToggle options (can choose multiple)
radioSelect one option from a group
submitSubmit form
resetReset form fields
fileUpload files
date, timePick date or time

⚙️ 5. HTML Input Attributes

AttributePurpose
nameKey for submitted form data
valuePredefined value
placeholderHint text inside input
requiredMakes input mandatory
readonlyPrevents editing
disabledDisables the input entirely
maxlengthLimits character count
min / maxNumeric range enforcement
patternCustom regex for validation
autocompleteSuggest previous entries

✅ Key Takeaway

  • Use <form> to group inputs for data submission
  • Choose appropriate input types and attributes for user needs
  • Always pair <label> with inputs for accessibility
  • Combine client-side and server-side validation for security
  • Understand when to use GET vs POST methods depending on data sensitivity