HTML FORM ELEMENTS
HTML form elements are used to collect user input. The most common form elements are listed below:
| Element | Description | Example |
|---|---|---|
<form> | Defines an HTML form | <form>...</form> |
<input> | Creates input fields (text, password, email, etc.) | <input type="text"> |
<label> | Defines a label for an input field | <label>Name:</label> |
<textarea> | Creates a multi-line text input | <textarea></textarea> |
<button> | Creates a clickable button | <button>Submit</button> |
<select> | Creates a drop-down list | <select>...</select> |
<option> | Defines options in a drop-down list | <option>India</option> |
<optgroup> | Groups related options in a drop-down | <optgroup label="Asia"> |
<fieldset> | Groups related form elements | <fieldset>...</fieldset> |
<legend> | Adds a caption to a fieldset | <legend>Personal Details</legend> |
<datalist> | Provides predefined suggestions for an input | <datalist>...</datalist> |
<output> | Displays the result of a calculation | <output>100</output> |
Common <input> Types
-
text– Single-line text input -
password– Password field -
email– Email address -
number– Numeric input -
tel– Telephone number -
url– Website URL -
search– Search field -
date– Date picker -
time– Time picker -
datetime-local– Date and time picker -
month– Month picker -
week– Week picker -
color– Color picker -
range– Slider control -
radio– Radio button -
checkbox– Checkbox -
file– File upload -
hidden– Hidden field -
submit– Submit button -
reset– Reset button -
image– Image as a submit button
Example
<!DOCTYPE html>
<html>
<head>
<title>HTML Form Example</title>
</head>
<body>
<form action="submit.php" method="post">
<label for="name">Name:</label>
<input type="text" id="name" name="name"><br><br>
<label for="email">Email:</label>
<input type="email" id="email" name="email"><br><br>
<label>Gender:</label>
<input type="radio" name="gender" value="Male"> Male
<input type="radio" name="gender" value="Female"> Female
<br><br>
<label>Hobbies:</label>
<input type="checkbox" name="sports"> Sports
<input type="checkbox" name="music"> Music
<br><br>
<label for="country">Country:</label>
<select id="country">
<option>India</option>
<option>USA</option>
<option>Canada</option>
</select>
<br><br>
<label for="message">Message:</label><br>
<textarea id="message" rows="4" cols="30"></textarea>
<br><br>
<button type="submit">Submit</button>
<button type="reset">Reset</button>
</form>
</body>
</html>
These are the essential HTML form elements used to create interactive forms for collecting user information.
Comments
Post a Comment