Skip to content

multipart/alternative MIME Type — Meaning, Usage & Examples

multipart/alternative
Extensions: — Class: multipart Spec: RFC 2046 (IANA registered)
View IANA registration ↗

multipart/alternative means: multipart/alternative is the media type for a message whose parts are different representations of the same content, ordered from least to most preferred. The receiver chooses the last part it can render, which is how HTML email ships both a plain-text and an HTML version. Multipart media types bundle several independent body parts into one message, separated by a boundary token declared in the Content-Type header. They are the backbone of HTML file uploads and mixed payloads. The boundary parameter is mandatory and must not appear inside any part, or parsers split the message at the wrong place and corrupt the upload. You will encounter multipart/alternative in contexts such as html email with a plain-text fallback part; messages offering multiple equivalent formats for client negotiation; accessibility-friendly content with simpler alternatives. It is commonly associated with the file extension(s) no fixed file extension. Order matters: place the plainest version first and the richest last, because clients pick the most preferred part they support. Putting HTML first can cause plain-text clients to show raw markup.

Advertisement
Ad slot · ref-top

When you'll see multipart/alternative

  • HTML email with a plain-text fallback part
  • Messages offering multiple equivalent formats for client negotiation
  • Accessibility-friendly content with simpler alternatives

How to handle it

When constructing a multipart body, let your HTTP library generate the boundary and assemble the parts — hand-rolling boundaries is error-prone. Each form-data part needs a Content-Disposition with a name, and file parts need a filename and their own Content-Type. On the server, use a streaming multipart parser to avoid buffering large uploads entirely in memory, and enforce size limits per part and per request. As a final checklist for multipart types: let libraries generate boundaries, stream-parse large uploads with per-part and per-request size limits, give each file part its own Content-Type, and reject unexpected parts early so malformed or oversized messages never exhaust server memory.

Notes & gotchas

Order matters: place the plainest version first and the richest last, because clients pick the most preferred part they support. Putting HTML first can cause plain-text clients to show raw markup.

Examples

HTTP
HTTP/1.1 200 OK
Content-Type: multipart/alternative
Content-Length: 84

Sample multipart/alternative content delivered with the correct Content-Type header.
curl
curl -i -H "Accept: multipart/alternative" https://api.example.com/v1/resource   # inspect the returned Content-Type
JavaScript (fetch)
const res = await fetch("/v1/resource", { headers: { Accept: "multipart/alternative" } });
// verify res.headers.get("Content-Type") starts with "multipart/alternative"
const text = await res.text();   // handle according to the declared type
Python (requests)
import requests

res = requests.get("https://api.example.com/v1/resource",
                   headers={"Accept": "multipart/alternative"}, timeout=10)
res.raise_for_status()
# confirm the server declared the expected type
assert res.headers["Content-Type"].startswith("multipart/alternative")
text = res.text   # decode/handle according to the type

Frequently asked questions

Why does my HTML email show raw tags in some clients?

Because the plain-text alternative is missing or ordered after the HTML part. Include a text/plain part first, then text/html, so text-only clients render the readable version.

Is multipart/alternative used outside email?

Rarely in HTTP; it is primarily a MIME email construct. The same negotiation idea in HTTP is handled by Accept headers and content negotiation instead.

Why is the boundary parameter required for multipart types?

It delimits the parts. The sender generates a unique token, declares it in Content-Type, and writes it between parts. If the token occurs inside a part's data, the parser splits incorrectly — libraries generate collision-safe boundaries for you.

What is the difference between multipart/form-data and multipart/mixed?

form-data is for HTML form submissions and file uploads (each part has a name and optional filename); mixed is a general container for unrelated parts. Browsers' FormData API produces form-data automatically with a correct boundary.

Why is my multipart upload rejected as malformed?

Usually the boundary in the Content-Type header does not match the delimiters in the body, or a part is missing its Content-Disposition. Let your HTTP library build the body so the boundary and parts stay consistent.

Advertisement
Ad slot · ref-in-article

Try the URL Encoder

Percent-encode and decode URL components or full URLs.

Open tool →