HTML Form Tag
The <form> tag in HTML is used to create an interactive form for user input. It can include fields like text boxes, radio buttons, checkboxes, and submit buttons.
Basic Structure
Here is a simple form with text input and a submit button:
<form action="submit.php" method="post">
<label for="name">Name:</label>
<input type="text" id="name" name="name"><br><br>
<input type="submit" value="Submit">
</form>
Important Attributes
action– Specifies where to send the form data.method– Determines the HTTP method (e.g.,getorpost).name– Used to reference form controls in scripts or backend.
Common Form Elements
<input>– For user input (text, password, radio, etc.).<textarea>– For multiline text input.<select>– For dropdown lists.<button>– For clickable buttons.<label>– Associates a label with an input element.
Example with Multiple Inputs
This example demonstrates different input types in a form:
<form action="submit.php" method="post">
<label for="email">Email:</label>
<input type="email" id="email" name="email"><br><br>
<label>
<input type="checkbox" name="subscribe"> Subscribe to newsletter
</label><br><br>
<label>Gender:</label><br>
<input type="radio" name="gender" value="male"> Male<br>
<input type="radio" name="gender" value="female"> Female<br><br>
<input type="submit" value="Register">
</form>