HTML formenctype Attribute

Beginner
⏱️ 5 min read
📚 Updated: Jun 2026
🎯 3 Examples
Forms & Input

What You’ll Learn

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.

01

Override enctype

Per-button encoding.

02

File Uploads

multipart/form-data.

03

Default URL

x-www-form-urlencoded.

04

Submit Buttons

button and input.

05

JavaScript

Toggle encoding.

06

vs enctype

Form default vs override.

Purpose of formenctype Attribute

The 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.

💡
File uploads require multipart/form-data

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.

📝 Syntax

Add formenctype to a submit button with one of the supported MIME type values:

formenctype.html
<form action="/upload" method="post">
  <input type="file" name="file">
  <input type="submit" value="Upload File" formenctype="multipart/form-data">
</form>

Syntax Rules

  • Valid on submit controls: <button type="submit">, <input type="submit">, and <input type="image">.
  • Overrides the parent form’s enctype only for that button’s submission.
  • Only meaningful with method="post" (GET forms ignore enctype).
  • Works alongside formaction and formmethod for full per-button control.

💎 Values

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.
formenctype-values.html
<!-- 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">

⚡ Quick Reference

Encoding ValueUse CaseNotes
application/x-www-form-urlencodedText fields, search formsDefault if not specified
multipart/form-dataFile uploadsRequired for type="file"
text/plainSimple plain-text payloadsRare; limited character handling
Attribute onSubmit buttonsOverrides form enctype
Requiresmethod="post"GET ignores encoding type
JS propertybutton.formEnctypeRead/write encoding string

Applicable Elements

ElementSupported?Notes
<input type="submit">YesMost common use
<button type="submit">YesSemantic submit buttons
<input type="image">YesImage-based submit control
<form>NoForms use enctype; buttons use formenctype
<input type="file">NoFile inputs need correct encoding on submit

Form enctype vs formenctype

AttributeOnBehavior
enctype<form>Default encoding for all submit buttons
formenctypeSubmit button / inputOverrides enctype for that button only

Examples Gallery

File upload with multipart encoding, mixed encoding in one form, and toggling formenctype dynamically with JavaScript.

👀 Live Preview

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

Implementation Example — File Upload

Let’s look at an example of how to use the formenctype attribute in an HTML form:

index.html
<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>
Try It Yourself

How It Works

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.

Example — Mixed Encoding in One Form

Alternatively, set enctype on the form for uploads and use default encoding on a separate text-only submit:

mixed-encoding.html
<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>
Try It Yourself

How It Works

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.

Dynamic Values with JavaScript

You can dynamically set the formenctype attribute using JavaScript when encoding should change based on user interaction:

index.html
<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>
Try It Yourself

How It Works

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.

♿ Accessibility

  • Label file inputs clearly — Users uploading files need to know what type and size of file is expected.
  • Describe upload requirements in text — Do not rely on encoding attributes alone; explain accepted formats in plain language.
  • Provide error feedback — If encoding or upload fails server-side, return clear messages users can understand.
  • Keep submit buttons distinct — When multiple buttons use different encoding, label them so users know what each does.

🧠 How formenctype Works

1

Form defines default enctype

Usually URL-encoded unless set otherwise.

Markup
2

Button may override with formenctype

Submit control picks a different encoding.

Override
3

Browser packages the payload

Data is encoded as multipart parts or URL pairs.

Encode
=

Correct encoding, reliable uploads

Server receives data in the format it expects.

Browser Support

The formenctype attribute is supported in all modern browsers. It is part of the HTML5 form submission override attributes.

HTML5 · Fully supported

Universal encoding override

All major browsers honor formenctype on submit controls.

99% Browser support
Google Chrome Fully supported
Full support
Mozilla Firefox Fully supported
Full support
Apple Safari Fully supported
Full support
Microsoft Edge Fully supported
Full support
formenctype attribute 99% supported

Bottom line: Use formenctype confidently for per-button encoding; set enctype on the form when all submissions share the same encoding.

💡 Best Practices

✅ Do

  • Choose encoding based on the data being submitted
  • Use multipart/form-data when the form includes file uploads
  • Use application/x-www-form-urlencoded for standard text fields
  • Set enctype on the form when all buttons share the same encoding
  • Use method="post" whenever encoding matters

❌ Don’t

  • Submit files without multipart/form-data
  • Rely on text/plain for complex or international text
  • Put formenctype on non-submit controls
  • Expect encoding attributes to work with method="get"
  • Forget server-side validation of uploaded file types and sizes

Conclusion

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.

Key Takeaways

Knowledge Unlocked

Five truths every developer should know about formenctype

Bookmark these before your next upload form.

5
Core concepts
📁 02

multipart

For file uploads.

Value
🔗 03

URL-encoded

Default for text.

Value
⚙️ 04

POST only

GET ignores it.

Method
📄 05

Submit only

button and input.

Scope

❓ Frequently Asked Questions

It overrides the form’s enctype encoding for the submit button that was clicked, controlling how data is packaged before sending.
Whenever the form includes <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.
No. Encoding type only applies to method="post" submissions. GET forms append data to the URL instead.
Use buttonElement.setAttribute('formenctype', 'multipart/form-data') or assign buttonElement.formEnctype.
Yes in all modern browsers. IE 10+ also supports formenctype on submit controls.

Build correct upload forms

Practice file upload encoding with formenctype in the Try It editor.

Try file upload example →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

3 people found this page helpful