Interesting Facts About HTML Forms
Last Updated :
05 Mar, 2025
HTML forms are an essential part of web development, allowing users to interact with websites by inputting data. Whether it's a login form, registration page, or contact form, they serve as the primary means of communication between users and web applications.
1. form Attribute Allows Inputs Outside the <form> Tag
The form attribute allows you to associate an input element with a form even if it’s located outside the <form> tag. This is particularly useful for complex layouts where form elements are scattered across the page.
HTML
<form id="myForm" action="/submit" method="post"></form>
<input type="text" name="username" form="myForm" />
<button type="submit" form="myForm">Submit</button>
2. formtarget Attribute Controls Where the Response Opens
The formtarget
attribute can be used with <input type="submit">
or <button>
to specify where the form response should be displayed, such as opening it in a new tab or window.
HTML
<button type="submit" formtarget="_blank">Submit and Open in New Tab</button>
3. Forms Can Submit Data to Different HTTP Methods
While GET and POST are the most common methods, HTML forms also support PUT, DELETE, and other HTTP methods using the method attribute. However, browser support for non-GET/POST methods is limited, and these methods are often handled using JavaScript or server-side logic.
HTML
<form action="/update" method="PUT">
<input type="text" name="data">
<button type="submit">Update</button>
</form>
4. Accept-charset Attribute Specifies Character Encoding
The accept-charset attribute allows you to specify the character encoding used when the form is submitted. UTF-8 is the most commonly used encoding.
HTML
<form action="/submit" method="post" accept-charset="UTF-8"></form>
5. Formaction Attribute Overrides the Form’s action
The formaction attribute can be used on <input type="submit"> or <button> to override the form’s action attribute. This allows you to submit the same form data to different endpoints based on which button is clicked.
HTML
<form action="/default" method="post">
<input type="submit" value="Submit to Default" />
<input type="submit" formaction="/alternate" value="Submit to Alternate" />
</form>
6. Formnovalidate Attribute Bypasses Validation
The formnovalidate attribute can be added to a submit button to bypass form validation. This is useful for "Save Draft" buttons where incomplete or invalid data might be acceptable.
HTML
<form action="/submit" method="post">
<input type="text" name="email" required />
<input type="submit" value="Submit" />
<input type="submit" formnovalidate value="Save Draft" />
</form>
7. Form can Be Reset
You can reset all form fields to their default values using the <input type="reset"> button or by calling the reset() method in JavaScript.
HTML
<form>
<input type="text" name="name" value="Default">
<input type="reset" value="Reset">
</form>
8. Forms Can Be Nested
HTML technically allows nesting forms, but it’s not recommended because the behavior is undefined in most browsers. Only the outermost form will be submitted.
HTML
<form id="form1">
<input type="text" name="field1">
<form id="form2">
<input type="text" name="field2">
</form>
</form>
9. Forms Can Upload Files
The <input type="file"> element allows users to upload files. You can restrict file types using the accept attribute. For example, to allow only .jpg and .png files:
HTML
<input type="file" name="file" accept="image/jpeg, image/png">
Similar Reads
HTML Interview Questions and Answers HTML (HyperText Markup Language) is the foundational language for creating web pages and web applications. Whether you're a fresher or an experienced professional, preparing for an HTML interview requires a solid understanding of both basic and advanced concepts. Below is a curated list of 50+ HTML
14 min read
Can we Create a Nested Form in HTML ? In HTML nesting forms means placing one <form> element inside another is not allowed, although, multiple forms can be possible to create. The HTML specification explicitly specifies that forms cannot be nested. Nesting forms can lead to unexpected behavior and conflicts between forms. As a res
3 min read
How to add a checkbox in forms using HTML ? In this article, we will learn how to add a checkbox in HTML Forms. Basically, the checkbox is used to select one or more options from a variety of options. It is a multi-control unit that will be presented as a small square box on the screen. Normally, Checkbox has 3 states namely- Checked, uncheck
1 min read
HTML <input> form Attribute The HTML <input> form Attribute is used to specify interactive input fields for web-based forms. A form can contain multiple input fields to accept inputs from the users. It is the most powerful element in HTML. Syntax: <input form="form_id"> Attribute Value: This attribute contains a si
1 min read
How to use formaction attribute in HTML ? In this article, we will learn how to use the formaction attribute in HTML. Basically, the information attribute is used to define where to send the data of the form after submitting the form the working of formaction will begin. It overrides the feature of the action attribute of the <form> e
2 min read
How to define a form for user input using HTML5 ? In this article, we will learn how to create a form in a webpage by using the <form> tag. This tag is used to create form for user input. Also there are many elements which are used within form tag. Syntax: <form> Form Content... </form> Example: The following code snippet demonstr
1 min read