HTML formenctype Attribute
The HTML formenctype attribute specifies how form data is encoded when a particular submit button is used. It overrides the enctype attribute of the button's associated <form> element for that submission.
Syntax
The formenctype attribute is placed on a submit button and specifies the encoding type used when that button submits its associated form.
<button type="submit" formenctype="multipart/form-data">Submit</button>
It can also be used with an <input> element when the input is a submit button.
<input type="submit" value="Submit" formenctype="text/plain">
Elements That Use the formenctype Attribute
The formenctype attribute is an attribute for form submission and applies to elements that act as submit buttons.
| Element | Description |
|---|---|
<button> |
Specifies an alternate encoding type when the element is a submit button. |
<input type="submit"> |
Specifies an alternate encoding type for a submit input. |
<input type="image"> |
Specifies an alternate encoding type for an image submit button. |
Attribute Values
The formenctype attribute accepts the same three encoding types as the enctype attribute.
| Value | Description |
|---|---|
application/x-www-form-urlencoded |
Uses URL-encoded form data. This is the default encoding type. |
multipart/form-data |
Encodes the form as multiple parts and is required when transmitting uploaded file contents. |
text/plain |
Encodes the form data as plain text. This format is mainly useful for debugging rather than normal form processing. |
If an invalid value is specified, the encoding type defaults to application/x-www-form-urlencoded.
Overriding the Form enctype
A form can define its normal encoding with the enctype attribute. When the submit button used to submit the form has a formenctype attribute, the button's encoding type is used instead.
<form action="result.php" method="post" enctype="application/x-www-form-urlencoded">
<input type="text" name="message">
<button type="submit">Normal Submit</button>
<button type="submit" formenctype="multipart/form-data">Multipart Submit</button>
</form>
The Normal Submit button uses the form's enctype, while the Multipart Submit button overrides it with multipart/form-data.
Uploading Files
The multipart/form-data encoding type is necessary when the submitted form data includes the contents of files selected with <input type="file">.
<form action="upload.php" method="post">
<input type="file" name="document">
<button type="submit" formenctype="multipart/form-data">Upload File</button>
</form>
In this example, the form does not need to specify enctype="multipart/form-data" because the submit button supplies that encoding for the submission it initiates.
Related Form Attributes
The formenctype attribute belongs to a group of submit-button attributes that can override submission settings defined by the associated form.
| Submit Button Attribute | Form Attribute Overridden |
|---|---|
formaction |
action |
formenctype |
enctype |
formmethod |
method |
formnovalidate |
novalidate |
formtarget |
target |
Common Mistakes
Do not confuse formenctype with enctype. The enctype attribute defines the form's normal encoding type, while formenctype overrides that setting for a particular submit button.
Do not use formenctype on ordinary controls that do not act as submit buttons. For <input>, it applies to the submit and image states.
When transmitting uploaded file contents, make sure the submission uses multipart/form-data.
Browser Support
Baseline: Widely available indicates a feature has been supported by core browsers for at least 30 months. At this stage, the feature is considered stable and safe for most websites to use without needing to worry about compatibility issues or fallbacks, as it is supported by the vast majority of users' devices and browser versions.
The formenctype attribute is widely supported on submit-capable <button> and <input> elements in current core browsers.
Checking Browser Support
For current browser compatibility information, visit Can I Use? . Search for the HTML element or attribute you want to check. You can also narrow your search by entering an element name and attribute name separated by a colon. Search results can include related HTML features, element attributes, input types, APIs, and other technologies, so select the result that most closely matches the feature you are checking.
Try the formenctype Attribute
The example uses two submit buttons. One uses the form's normal encoding type, while the other uses formenctype="text/plain" to override it for that submission.
Summary
The HTML formenctype attribute specifies the encoding type used when a particular submit button submits its associated form. It can override the form's enctype setting with application/x-www-form-urlencoded, multipart/form-data, or text/plain.
