👀 Live Preview
File upload form with formenctype="multipart/form-data" on the submit button:

The formenctype attribute is an essential part of HTML forms, allowing developers to specify how form data should be encoded before it is sent to the server. Applied to submit buttons, it overrides the form’s default enctype for that one submission—crucial when file uploads need multipart/form-data.
Per-button encoding.
multipart/form-data.
x-www-form-urlencoded.
button and input.
Toggle encoding.
Form default vs override.
formenctype AttributeThe primary purpose of the formenctype attribute is to specify the encoding type for form data when it is submitted via a particular button. This encoding type determines how the data is packaged and sent to the server. Different encoding types suit different data—text fields, file uploads, or plain text.
While most forms set enctype once on the <form> element, formenctype lets one form offer multiple submit paths with different encoding requirements.
Without the correct encoding, file inputs will not transmit binary data properly. Set formenctype="multipart/form-data" on the upload submit button, or use enctype on the form.
Add formenctype to a submit button with one of the supported MIME type values:
<form action="/upload" method="post">
<input type="file" name="file">
<input type="submit" value="Upload File" formenctype="multipart/form-data">
</form><button type="submit">, <input type="submit">, and <input type="image">.enctype only for that button’s submission.method="post" (GET forms ignore enctype).formaction and formmethod for full per-button control.The formenctype attribute accepts several values to define different encoding types. The common values include:
application/x-www-form-urlencoded — The default value. URL-encodes form data before sending. Suitable for standard text fields.multipart/form-data — Used when the form includes file uploads. Sends each field and file as a separate part for efficient binary transmission.text/plain — Sends data as plain text with spaces encoded as + characters. Rarely used; not ideal for structured or special-character data.<!-- Default text encoding -->
<input type="submit" formenctype="application/x-www-form-urlencoded">
<!-- File upload encoding -->
<input type="submit" formenctype="multipart/form-data">
<!-- Plain text (uncommon) -->
<input type="submit" formenctype="text/plain">| Encoding Value | Use Case | Notes |
|---|---|---|
application/x-www-form-urlencoded | Text fields, search forms | Default if not specified |
multipart/form-data | File uploads | Required for type="file" |
text/plain | Simple plain-text payloads | Rare; limited character handling |
| Attribute on | Submit buttons | Overrides form enctype |
| Requires | method="post" | GET ignores encoding type |
| JS property | button.formEnctype | Read/write encoding string |
| Element | Supported? | Notes |
|---|---|---|
<input type="submit"> | Yes | Most common use |
<button type="submit"> | Yes | Semantic submit buttons |
<input type="image"> | Yes | Image-based submit control |
<form> | No | Forms use enctype; buttons use formenctype |
<input type="file"> | No | File inputs need correct encoding on submit |
enctype vs formenctype| Attribute | On | Behavior |
|---|---|---|
enctype | <form> | Default encoding for all submit buttons |
formenctype | Submit button / input | Overrides enctype for that button only |
File upload with multipart encoding, mixed encoding in one form, and toggling formenctype dynamically with JavaScript.
File upload form with formenctype="multipart/form-data" on the submit button:
Let’s look at an example of how to use the formenctype attribute in an HTML form:
<form action="/upload" method="post">
<label for="file">Choose a file:</label>
<input type="file" id="file" name="file">
<input type="submit" value="Upload File" formenctype="multipart/form-data">
</form>In this example, the formenctype attribute is set to multipart/form-data to indicate that the form data includes file uploads. This ensures that files are properly transmitted to the server.
Alternatively, set enctype on the form for uploads and use default encoding on a separate text-only submit:
<form action="/handler" method="post" enctype="multipart/form-data">
<input type="text" name="title">
<input type="file" name="attachment">
<input type="submit" value="Upload with file">
<input type="submit" value="Save text only"
formenctype="application/x-www-form-urlencoded">
</form>When the form already has enctype="multipart/form-data", a second submit button can use formenctype to fall back to standard URL encoding for submissions that do not need file data.
You can dynamically set the formenctype attribute using JavaScript when encoding should change based on user interaction:
<form id="myForm" action="/upload" method="post">
<label for="file">Choose a file:</label>
<input type="file" id="file" name="file">
<label>
<input type="checkbox" id="toggleEnctype">
Use <code>multipart/form-data</code>
</label>
<input type="submit" id="submitBtn" value="Upload File">
</form>
<script>
const submitBtn = document.getElementById("submitBtn");
const toggle = document.getElementById("toggleEnctype");
toggle.addEventListener("change", () => {
if (toggle.checked) {
submitBtn.setAttribute("formenctype", "multipart/form-data");
} else {
submitBtn.removeAttribute("formenctype");
}
});
</script>When the checkbox is checked, the script sets formenctype="multipart/form-data" on the submit button so file data is encoded correctly. When unchecked, the attribute is removed and the form falls back to its default encoding.
Usually URL-encoded unless set otherwise.
Submit control picks a different encoding.
Data is encoded as multipart parts or URL pairs.
Server receives data in the format it expects.
The formenctype attribute is supported in all modern browsers. It is part of the HTML5 form submission override attributes.
All major browsers honor formenctype on submit controls.
Bottom line: Use formenctype confidently for per-button encoding; set enctype on the form when all submissions share the same encoding.
multipart/form-data when the form includes file uploadsapplication/x-www-form-urlencoded for standard text fieldsenctype on the form when all buttons share the same encodingmethod="post" whenever encoding mattersmultipart/form-datatext/plain for complex or international textformenctype on non-submit controlsmethod="get"The formenctype attribute is a crucial aspect of HTML forms, allowing developers to control how form data is encoded and transmitted to the server. By understanding and utilizing this attribute effectively, you can ensure the proper handling and processing of form submissions on your website.
For most file-upload forms, set enctype="multipart/form-data" on the form itself. Reach for formenctype when individual submit buttons in the same form need different encoding behavior.
formenctypeBookmark these before your next upload form.
Per submit button.
PurposeFor file uploads.
ValueDefault for text.
ValueGET ignores it.
Methodbutton and input.
Scopeenctype encoding for the submit button that was clicked, controlling how data is packaged before sending.<input type="file"> or other binary data that must be sent as separate parts.enctype is on the <form> as the default. formenctype on a submit button overrides it for that button only.method="post" submissions. GET forms append data to the URL instead.buttonElement.setAttribute('formenctype', 'multipart/form-data') or assign buttonElement.formEnctype.Practice file upload encoding with formenctype in the Try It editor.
3 people found this page helpful