HTML Forms


Forms

We use HTML Forms for Collecting user page in website.For example, when we sign up in any website they take Name, Age , EmailId of the user.

Form tags are start with <form> and ends with </form>

A Sample Form Example

<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<form>
<label for="fname">First name:</label>
<input type="text" id="fname" name="fname">
<label for="lname">Last name:</label>
<input type="text" id="lname" name="lname">
</form>
</body>
</html>

HTML Form Elements

Sr.No Element Name
1 <input>
2 <label>
3 <select>
4 <textarea>
5 <button>
6 <fieldset>
7 <legend>
8 <datalist>
9 <option>

HTML Form Attributes

Attributes are used in a form to perform various actions in a form.

1. Action – Server Url where the data will be submitted or fetch
2. Target – Tells about the location where the response will be displayed
3. Method – Tells whether data is POST or GET , HTTP Method
4. Autocomplete – Tells Autocomplete is off or on
5. Novalidate – It validate the form data will be validated or not

Another HTML Form Example

<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<form action="/action_page.php" target="_blank" method="post" autocomplete="on"novalidate>
<label for="fname">First name:</label>
<input type="text" id="fname" name="fname">
<label for="lname">Last name:</label>
<input type="text" id="lname" name="lname">
</form>
</body>
</html>