HTML enctype Attribute

Beginner
5 min read
Updated: Oct 2026
3 examples
Live preview

Definition and Usage

The enctype attribute on a <form> sets the MIME type of the request body when the form is submitted with method="post". It controls how field names and values are packed for the server.

The default is application/x-www-form-urlencoded. Use multipart/form-data when the form includes <input type="file"> (often with accept). A submit control can override this with formenctype.

Baseline · Widely available.

Not deprecated and not experimental. Long-supported form submission attribute across modern browsers.

POST only.

enctype is ignored for method="get" (data goes in the URL). File uploads need method="post" and enctype="multipart/form-data".

HTML Syntax

syntax.html
<form method="post" enctype=" type">

In JavaScript: form.enctype = "multipart/form-data" (or read form.enctype).

Attribute Values

Three MIME types (case-insensitive):

ValueDescriptionTry it
application/x-www-form-urlencodedDefault — URL-encoded name=value pairsTry it
multipart/form-dataRequired for file uploads — binary-safe partsTry it
text/plainMostly for debugging — not for production or filesTry it
formenctypeOverride on a specific submit controlTry it

Live Preview

Change enctype on the demo form, then submit (navigation is blocked) to see the value the browser would use.

Applies only with method="post". Submit shows the current encoding type.

Form

enctype = application/x-www-form-urlencoded

HTML Examples

Short, copy-ready snippets. Use Try It Yourself for a live editor.

Example 1 — Default URL Encoding

Omit enctype (or set it explicitly) for normal text fields.

HTML
<form action="/submit" method="post">
  <label for="email">Email</label>
  <input id="email" name="email" type="email">
  <button type="submit">Send</button>
</form>
Try It Yourself

How It Works

  1. method="post" puts fields in the request body.
  2. No enctype → browser uses urlencoded.
  3. Body looks like email=alex%40example.com.
  4. Fine for text, checkboxes, and selects — not for files.

Example 2 — File Upload Encoding

File inputs require multipart/form-data.

HTML
<form action="/upload" method="post" enctype="multipart/form-data">
  <label for="photo">Photo</label>
  <input id="photo" name="photo" type="file" accept="image/*">
  <button type="submit">Upload</button>
</form>
Try It Yourself

How It Works

  1. type="file" selects a binary file.
  2. enctype="multipart/form-data" wraps fields in MIME parts.
  3. method must be post — GET cannot carry file bodies.
  4. Server reads multipart parts (frameworks usually handle this).

Example 3 — text/plain (Debugging)

Rare encoding — useful to inspect raw name/value lines, not for real apps.

HTML
<form action="/debug" method="post" enctype="text/plain">
  <label for="note">Note</label>
  <input id="note" name="note" type="text" value="hello world">
  <button type="submit">Debug submit</button>
</form>
Try It Yourself

How It Works

  1. enctype="text/plain" sends mostly unescaped text lines.
  2. Spaces and symbols are not safely encoded like urlencoded.
  3. Not for files — still use multipart for uploads.
  4. Prefer urlencoded or multipart for real servers.

Edge Cases & Pitfalls

Most upload bugs are a missing multipart value or using GET.

files

File + default enctype fails

A file field with the default urlencoded encoding will not send usable binary data. Always pair files with multipart/form-data.

method

GET ignores enctype

Query strings cannot carry multipart bodies. Uploads need method="post".

override

formenctype wins per click

A submit button’s formenctype overrides the form for that submission only — useful when one form has two submit modes.

debug

text/plain is not for apps

Servers and frameworks expect urlencoded or multipart. Keep text/plain for experiments.

ajax

Fetch/XHR set their own headers

If you build the body in JavaScript (FormData, JSON), the form’s enctype does not apply — you set Content-Type (or let the browser set the multipart boundary).

Browser Support

enctype is an HTML form attribute in the browser. It is not a Node.js, Deno, or Bun API.

✓ Baseline · Widely available

enctype

Supported everywhere modern browsers run. All three MIME values work with method=post; multipart is required for file inputs.

98% Global support (approx.)
Google Chrome All
Full support
Mozilla Firefox All
Full support
Apple Safari All
Full support
Microsoft Edge All
Full support
Opera All
Full support
Samsung Internet Modern
Full support
Internet Explorer All
Supported
enctype Widely supported

Bottom line: Safe for all forms. Remember: multipart + POST for uploads; default urlencoded for ordinary fields.

Key Takeaways

  • On <form>: MIME type of the POST body.
  • Default: application/x-www-form-urlencoded.
  • Files: multipart/form-data + method="post".
  • Override: formenctype on a submit control.

One line: enctype chooses how POST form data is encoded — use multipart for files.

Frequently Asked Questions

On a form element, when method is post, enctype sets the MIME type of the request body: how field names and values are encoded before they are sent to the server.
application/x-www-form-urlencoded. Fields become URL-encoded name=value pairs joined with &.
Whenever the form has an input type=file. Binary file bytes cannot be sent correctly with the default urlencoded encoding.
No. GET appends data to the action URL query string. enctype only applies when the form is submitted with method=post (or when a submitter overrides method to post).
Mostly debugging. It sends mostly unencoded name=value lines. Do not use it for production forms or file uploads.
Yes. formenctype on a submit button, image input, or input type=submit overrides the form’s enctype for that submission.

Next: for

Connect a label to a control with matching id.

for tutorial →

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.

8 people found this page helpful