HTML input elements have special attributes that let you control how they interact with forms. These “form attributes” allow you to do things like place inputs outside a form, override form actions, or skip validation for specific buttons.
The form Attribute
The form attribute lets you place an input field outside of a form tag, but still have it belong to that form. The value must match the id of the form.
The formaction Attribute
The formaction attribute lets you send the form data to different URLs depending on which button the user clicks. This overrides the form’s main action attribute.
The formenctype Attribute
The formenctype attribute specifies how form data should be encoded when submitted. This is especially important for file uploads. It overrides the form’s enctype attribute.
The formmethod Attribute
The formmethod attribute lets you override the form’s HTTP method. One button can use GET while another uses POST. This overrides the form’s method attribute.
The formtarget Attribute
The formtarget attribute specifies where to display the response after submitting the form. You can open the result in a new tab or the same window. This overrides the form’s target attribute.
The formnovalidate Attribute
The formnovalidate attribute lets you skip validation for a specific submit button. This is useful when you want a “Save Draft” button that does not require all fields to be valid. This overrides the form’s novalidate attribute.
The novalidate Attribute (Form Level)
The novalidate attribute is applied to the <form> element itself. It turns off ALL validation for the entire form. No fields will be validated before submission.
Quick Summary
form– Connect an input outside a form to that form using the form’s IDformaction– Override where the form data is sent (different URLs for different buttons)formenctype– Override how form data is encoded (important for file uploads)formmethod– Override the HTTP method (GET vs POST)formtarget– Override where the response opens (same tab or new tab)formnovalidate– Skip validation for a specific submit button (like a “Save Draft” button)novalidate– Skip validation for the entire form (put on the form tag itself)
What Just Happened? Let Me Explain
- These form attributes give you fine-grained control over how your forms behave. You can have different buttons do different things.
- The
formattribute is very useful when you want to place inputs outside the form tag for layout reasons, but still have them submitted. - The
formactionattribute is great for having “Save Draft” vs “Publish” buttons that send data to different server scripts. - The
formenctype="multipart/form-data"is REQUIRED when you are uploading files. Without it, the file data will not be sent correctly. - The
formnovalidateandnovalidateattributes are useful for development or for saving drafts, but be careful: never trust client-side validation alone. Always validate on the server too.
HTML Form Input Attributes Reference
| Attribute | Description |
|---|---|
form | Specifies which form the input belongs to (by form ID) |
formaction | Overrides the form’s action URL (for submit buttons) |
formenctype | Overrides how form data is encoded (for submit buttons) |
formmethod | Overrides the HTTP method (GET or POST) for submit buttons |
formtarget | Overrides where to display the response (for submit buttons) |
formnovalidate | Skips validation for a specific submit button |
novalidate | Skips validation for the entire form (attribute on <form>) |
formaction, formenctype, formmethod, formtarget, and formnovalidate attributes only work on input types submit and image.