The Content-Type
entity header is used to indicate the {{Glossary("MIME type","media type")}} of the resource.
In responses, a Content-Type
header tells the client what the content type of the returned content actually is. Browsers will do MIME sniffing in some cases and will not necessarily follow the value of this header; to prevent this behavior, the header {{HTTPHeader("X-Content-Type-Options")}} can be set to nosniff
.
In requests, (such as {{HTTPMethod("POST")}} or {{HTTPMethod("PUT")}}), the client tells the server what type of data is actually sent.
Header type | {{Glossary("Entity header")}} |
---|---|
{{Glossary("Forbidden header name")}} | no |
Syntax
Content-Type: text/html; charset=utf-8 Content-Type: multipart/form-data; boundary=something
Directives
media-type
- The MIME type of the resource or the data.
- charset
- The character encoding standard.
- boundary
- For multipart entities the
boundary
directive is required, which consists of 1 to 70 characters from a set of characters known to be very robust through email gateways, and not ending with white space. It is used to encapsulate the boundaries of the multiple parts of the message.
Examples
Content-Type
in HTML forms
In a {{HTTPMethod("POST")}} request, resulting from an HTML form submission, the Content-Type
of the request is specified by the enctype
attribute on the {{HTMLElement("form")}} element.
<form action="/" method="post" enctype="multipart/form-data"> <input type="text" name="description" value="some text"> <input type="file" name="myFile"> <button type="submit">Submit</button> </form>
The request looks something like this (less interesting headers are omitted here):
POST /foo HTTP/1.1 Content-Length: 68137 Content-Type: multipart/form-data; boundary=---------------------------974767299852498929531610575 Content-Disposition: form-data; name="description" ---------------------------974767299852498929531610575 some text ---------------------------974767299852498929531610575 Content-Disposition: form-data; name="myFile"; filename="foo.txt" Content-Type: text/plain (content of the uploaded file foo.txt) ---------------------------974767299852498929531610575
Specifications
Specification | Title |
---|---|
{{RFC("7233", "Content-Type in multipart", "4.1")}} | Hypertext Transfer Protocol (HTTP/1.1): Range Requests |
{{RFC("7231", "Content-Type", "3.1.1.5")}} | Hypertext Transfer Protocol (HTTP/1.1): Semantics and Content |
Browser compatibility
The compatibility table in this page is generated from structured data. If you’d like to contribute to the data, please check out https://github.com/mdn/browser-compat-data/README.md and send us a pull request
{{Compat}}
See also
- {{HTTPHeader("Accept")}}
- {{HTTPHeader("Content-Disposition")}}
- {{HTTPStatus("206")}} Partial Content
- {{HTTPStatus("X-Content-Type-Options")}}