HTML Forms

HTML Tutorial

HTML Forms

HTML Forms are used to collect user input—like login details, contact messages, search queries, feedback, and registrations—and send that data to a server or handle it with JavaScript.

 1. Basic Form Structure

A form typically contains inputs, labels, and buttons.


 2. Simple Form Example

  •  Collects user data
  • Submit button sends the form

 3. Important <form> Attributes

action

URL where the form data is sent.

<form action="submit.php">

method

How data is sent.

MethodUse Case
GETSearch, filters (data visible in URL)
POSTLogin, signup (data hidden)

 Full Example


 4. Common Form Input Types

 Text Input


 Email Input

  •  Validates email format automatically

 Password Input


 Number Input


Radio Buttons

  •  Same name → only one selectable

Checkboxes


 Textarea

  •  Multi-line input

Select (Dropdown)


 5. Labels (Accessibility )

  •  Clicking label focuses input
  •  Better for screen readers

 6. Name Attribute (Very Important)

  • name is the key sent to server
  •  Without name, data is not submitted

 7. Required & Validation Attributes

Common attributes:

  • required

  • minlength, maxlength

  • pattern

  • placeholder


 8. Submit & Reset Buttons


 9. Form with JavaScript Validation (Basic)

  • Prevents empty submission

 10. GET vs POST (Quick Example)

GET

search.html?q=html

POST

Data sent securely in request body

 Common Mistakes

  •  Forgetting name attribute
  •  Using GET for passwords
  •  No labels (bad accessibility)
  •  Not validating inputs
  •  Inline styles everywhere

 Key Points to Remember

  • Forms collect user input

  • <form> wraps all controls

  • action + method are critical

  • name attribute sends data

  • Always validate input

  • Accessibility matters

You may also like...