HTML enctype Attribute

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

What You’ll Learn

The enctype attribute tells the browser how to encode form data in the request body when a form is submitted with method="post". Use the default for text fields, switch to multipart/form-data for file uploads, and understand when text/plain applies.

01

Form Only

On <form> tag.

02

URL-Encoded

Default encoding.

03

Multipart

For file uploads.

04

text/plain

Rare, unencoded.

05

POST Only

Ignored on GET.

06

JavaScript

form.enctype.

Purpose of enctype

The primary purpose of the enctype attribute is to define how the browser packages form field names and values before sending them to the server. Different data types need different encodings: simple text fields work with URL encoding, while binary files need multipart encoding.

Choosing the wrong enctype is a common cause of broken file uploads. If you include <input type="file"> but forget enctype="multipart/form-data", the server may receive corrupted or empty file data.

💡
Pair with method="post"

enctype controls the POST body format. GET forms put data in the URL query string, so enctype has no effect on GET submissions.

📝 Syntax

Add enctype to the opening <form> tag:

enctype.html
<form action="/upload" method="post" enctype="multipart/form-data">
  <input type="file" name="photo">
  <button type="submit">Upload</button>
</form>

Syntax Rules

  • Only valid on <form> elements.
  • Three standard values: URL-encoded (default), multipart, and text/plain.
  • Omit enctype on text-only POST forms; the default works.
  • Always set multipart/form-data when the form includes file inputs.

💎 Values

The enctype attribute accepts three MIME type values:

  • application/x-www-form-urlencoded — Default. Encodes fields as name=value pairs joined by &, with special characters percent-encoded.
  • multipart/form-data — Required for file uploads. Sends each field as a separate part, including binary file content.
  • text/plain — Rare. Sends unencoded plain text lines. Not recommended for production forms.
enctype-values.html
<!-- Default (text fields) -->
<form method="post" action="/contact">...</form>

<!-- File upload -->
<form method="post" action="/upload" enctype="multipart/form-data">...</form>

<!-- Plain text (debug only) -->
<form method="post" enctype="text/plain">...</form>

⚡ Quick Reference

Use Caseenctype ValueNotes
Login, contact, search POSTapplication/x-www-form-urlencodedDefault; omit attribute
File upload formmultipart/form-dataRequired with type=file
Debug / legacytext/plainAvoid in production
GET formN/Aenctype ignored
Applicable element<form>Form element only
JS propertyform.enctypeSame string values

Applicable Elements

ElementSupported?Notes
<form>YesPrimary and only standard use
<input>, <button>NoEncoding is set on the parent form

Encoding Types Compared

ValueBest ForRequest Body Shape
application/x-www-form-urlencodedText inputs, selects, textareasname=Jane&email=jane%40example.com
multipart/form-dataFile uploads + mixed fieldsSeparate parts with boundaries
text/plainDebugging onlyPlain lines like name=Jane

Examples Gallery

Default URL-encoded forms, multipart file uploads, dynamic enctype switching, and the rare text/plain value.

Example — Default vs Multipart

A text form uses the default encoding; a file upload form needs multipart/form-data:

enctype-forms.html
<form method="post" action="/submit">
  <input type="text" name="name">
</form>

<form method="post" action="/upload" enctype="multipart/form-data">
  <input type="file" name="file">
</form>
Try It Yourself

How It Works

The first form omits enctype, so the browser uses URL-encoded key-value pairs. The second form sets multipart/form-data so binary file bytes are transmitted correctly.

Dynamic Values with JavaScript

Switch enctype when the user adds a file to a mixed form:

dynamic-enctype.html
<form id="dynamicForm" method="post">
  <input type="file" id="file" name="file">
</form>

<script>
  fileInput.addEventListener("change", () => {
    form.enctype = fileInput.files.length
      ? "multipart/form-data"
      : "application/x-www-form-urlencoded";
  });
</script>
Try It Yourself

How It Works

One form can handle text-only or file submissions. JavaScript updates enctype before submit so the browser encodes the body correctly.

Example — text/plain

The text/plain value sends unencoded field data (rarely used in production):

text-plain.html
<form method="post" enctype="text/plain">
  <input type="text" name="message" value="Hello">
</form>

How It Works

With text/plain, the POST body contains readable lines like message=Hello without URL encoding. Most servers expect the default or multipart types instead.

♿ Accessibility

  • Label file inputs clearly — Users need to know what file type and size you accept before uploading.
  • Announce upload progress — Large multipart uploads should expose status to screen reader users.
  • Describe errors in plain language — If encoding or upload fails, explain what went wrong and how to fix it.
  • Do not rely on enctype alone — Server-side validation of file type and size is still required.

🧠 How enctype Works

1

Author sets enctype on form

Choose default, multipart, or text/plain.

Markup
2

User submits POST form

Browser packages fields per enctype rules.

Submit
3

HTTP body sent to server

Content-Type header matches enctype value.

Request
=

Server parses correctly

Text fields and files arrive in the expected format.

Browser Support

The enctype attribute is supported in all modern browsers on form elements. It has been part of HTML forms since early standards.

HTML4+ · Fully supported

Universal form encoding

All major browsers honor enctype on POST form submissions.

100% 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
enctype attribute 100% supported

Bottom line: Use multipart/form-data for every form that uploads files; the default handles everything else.

💡 Best Practices

✅ Do

  • Use multipart/form-data for any form with file inputs
  • Keep the default for text-only POST forms
  • Pair enctype with method="post" intentionally
  • Validate uploads on the server after submission
  • Switch enctype dynamically when files are optional

❌ Don’t

  • Upload files without multipart/form-data
  • Use text/plain in production applications
  • Assume enctype affects GET query strings
  • Set enctype on individual inputs instead of the form
  • Forget file size limits on the server

Conclusion

The enctype attribute is a crucial part of HTML forms. It controls how the browser encodes data in POST requests: URL-encoded pairs for everyday fields, multipart encoding for file uploads, and plain text for rare debugging scenarios.

Pick the right value, combine it with method and action, and validate data on the server for secure, reliable form handling.

Key Takeaways

Knowledge Unlocked

Five truths every developer should know about enctype

Bookmark these before your next upload form.

5
Core concepts
📝 02

Default

URL-encoded pairs.

Values
📁 03

Multipart

File uploads.

Uploads
⚙️ 04

POST Only

Ignored on GET.

Method
🔒 05

Server Check

Validate uploads.

Security

❓ Frequently Asked Questions

It specifies how form field data is encoded in the HTTP request body when a form is submitted with POST.
application/x-www-form-urlencoded. You do not need to set it explicitly on text-only forms.
Whenever the form includes <input type="file">. Without multipart encoding, file uploads will fail or corrupt.
No. GET forms append data to the URL query string. enctype only affects POST request bodies.
Yes. Set form.enctype or use form.setAttribute("enctype", "...") before submission.
Almost never in production. Use the default or multipart instead. text/plain is mainly for debugging or legacy scenarios.

Build correct upload forms

Practice multipart/form-data vs the default encoding in the Try It editor.

Try encoding comparison →

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