Open In App

Interesting Facts About HTML Forms

Last Updated : 05 Mar, 2025
Summarize
Comments
Improve
Suggest changes
Share
Like Article
Like
Report

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">



Article Tags :

Similar Reads