HTML <input> Tag โ User Input Field
๐ Introduction
The <input> tag is used to create interactive fields where users can enter data.
It is one of the most flexible HTML elements because it supports many types of input.
๐ <input> is a self-closing tag (no closing tag needed).
๐งฑ Syntax
<input type="text" />
๐ก Example
<!DOCTYPE html>
<html>
<head>
<title>Input Example</title>
</head>
<body>
<h2>Simple Form</h2>
<form>
<label>Name:</label>
<input type="text" />
<br /><br />
<label>Password:</label>
<input type="password" />
<br /><br />
<button type="submit">Submit</button>
</form>
</body>
</html>
๐ฅ๏ธ Output Explanation
- Users can type into input fields
- Each input type behaves differently
- Data can be submitted through a form
๐ฏ Common Input Types
1. Text Input
<input type="text" />
โ For names, messages, general text
2. Password Input
<input type="password" />
โ Hides characters for security
3. Email Input
<input type="email" />
โ Validates email format automatically
4. Number Input
<input type="number" />
โ Only allows numbers
5. Checkbox
<input type="checkbox" />
โ Used for options (yes/no, select multiple)
6. Radio Button
<input type="radio" name="gender" />
โ Select only one option
7. Submit Button
<input type="submit" />
โ Sends form data
๐ฏ Important Attributes
1. placeholder
<input type="text" placeholder="Enter your name" />
โ Shows hint inside input
2. value
<input type="text" value="anyName" />
โ Default value
3. name
<input type="text" name="username" />
โ Important for sending data to server
๐ง Important Concept
๐ <input> always works inside a <form>
๐งฉ Example Form with Inputs
<form>
<input type="text" placeholder="Name" /><br />
<input type="email" placeholder="Email" /><br />
<input type="password" placeholder="Password" /><br />
<input type="submit" value="Send" />
</form>
โ๏ธ Input vs Button
| Element | Purpose |
|---|---|
<input> |
Data entry |
<button> |
Action trigger |
๐ซ Common Mistakes
- Forgetting
typeโ - Not using
nameโ - Using input outside form โ
- Wrong input types โ
๐จ Styling Example
<input
type="text"
placeholder="Enter name"
style="padding:5px; border:1px solid gray;"
/>
๐งช Mini Exercise
Create a form with:
- Text input (name)
- Email input
- Password input
- Checkbox
- Submit button
- Use placeholders