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 submittedmethod
: HTTP method used for submission (GET
orPOST
)
⚙️ 2. Common <form>
Attributes
Attribute | Description |
---|---|
action | URL to which the form data is sent |
method | HTTP method: get or post |
autocomplete | Enables/disables autofill |
target | Specifies where to display the response |
novalidate | Disables built-in form validation |
enctype | Type of content used when sending data (for files) |
🧱 3. Common Form Elements
Element | Purpose |
---|---|
<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:
Type | Description |
---|---|
text | Single-line text input |
password | Hidden characters for passwords |
email | Validates email input |
number | Numeric input with optional range |
checkbox | Toggle options (can choose multiple) |
radio | Select one option from a group |
submit | Submit form |
reset | Reset form fields |
file | Upload files |
date , time | Pick date or time |
⚙️ 5. HTML Input Attributes
Attribute | Purpose |
---|---|
name | Key for submitted form data |
value | Predefined value |
placeholder | Hint text inside input |
required | Makes input mandatory |
readonly | Prevents editing |
disabled | Disables the input entirely |
maxlength | Limits character count |
min / max | Numeric range enforcement |
pattern | Custom regex for validation |
autocomplete | Suggest 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
vsPOST
methods depending on data sensitivity
Advertisement Slot 1
Advertisement Slot 2