Content-Disposition
In a regular HTTP response, the Content-Disposition response header is a header indicating if the content is expected to be displayed inline in the browser, that is, as a Web page or as part of a Web page, or as an attachment, that is downloaded and saved locally.
In a multipart/form-data body, the HTTP Content-Disposition general header is a header that can be used on the subpart of a multipart body to give information about the field it applies to. The subpart is delimited by the boundary defined in the Content-Type header. Used on the body itself, Content-Disposition has no effect.
The Content-Disposition header is defined in the larger context of MIME messages for e-mail, but only a subset of the possible parameters apply to HTTP forms and POST requests. Only the value form-data , as well as the optional directive name and filename , can be used in the HTTP context.
Header type | Response header (for the main body) General header (for a subpart of a multipart body) |
---|---|
Forbidden header name | no |
Syntax
As a response header for the main body
The first parameter in the HTTP context is either inline (default value, indicating it can be displayed inside the Web page, or as the Web page) or attachment (indicating it should be downloaded; most browsers presenting a ‘Save as’ dialog, prefilled with the value of the filename parameters if present).
Content-Disposition: inline Content-Disposition: attachment Content-Disposition: attachment; filename="filename.jpg"
As a header for a multipart body
The first parameter in the HTTP context is always form-data . Additional parameters are case-insensitive and have arguments that use quoted-string syntax after the ‘=’ sign. Multiple parameters are separated by a semi-colon ( ‘;’ ).
Content-Disposition: form-data Content-Disposition: form-data; name="fieldName" Content-Disposition: form-data; name="fieldName"; filename="filename.jpg"
Directives
The parameters filename and filename* differ only in that filename* uses the encoding defined in RFC 5987. When both filename and filename* are present in a single header field value, filename* is preferred over filename when both are understood.
Examples
A response triggering the «Save As» dialog:
200 OK Content-Type: text/html; charset=utf-8 Content-Disposition: attachment; filename="cool.html" Content-Length: 21 Save me!
This simple HTML file will be saved as a regular download rather than displayed in the browser. Most browsers will propose to save it under the cool.html filename (by default).
An example of an HTML form posted using the multipart/form-data format that makes use of the Content-Disposition header:
POST /test.html HTTP/1.1 Host: example.org Content-Type: multipart/form-data;boundary="boundary" --boundary Content-Disposition: form-data; name="field1" value1 --boundary Content-Disposition: form-data; name="field2"; filename="example.txt" value2 --boundary--
Specifications
Specification | Title |
---|---|
RFC 7578 | Returning Values from Forms: multipart/form-data |
RFC 6266 | Use of the Content-Disposition Header Field in the Hypertext Transfer Protocol (HTTP) |
RFC 2183 | Communicating Presentation Information in Internet Messages: The Content-Disposition Header Field |
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 and send us a pull request.
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | Android webview | Chrome for Android | Firefox for Android | Opera for Android | Safari on iOS | Samsung Internet | |
Content-Disposition | Chrome Full support Yes | Edge Full support 12 | Firefox Full support Yes | IE Full support Yes | Opera Full support Yes | Safari Full support Yes | WebView Android Full support Yes | Chrome Android Full support Yes | Firefox Android Full support Yes | Opera Android Full support Yes | Safari iOS Full support Yes | Samsung Internet Android Full support Yes |
Legend
Compatibility notes
- Firefox 5 handles the Content-Disposition HTTP response header more effectively if both the filename and filename* parameters are provided; it looks through all provided names, using the filename* parameter if one is available, even if a filename parameter is included first. Previously, the first matching parameter would be used, thereby preventing a more appropriate name from being used. See bug 588781.
See also
- HTML Forms
- The Content-Type defining the boundary of the multipart body.
- The FormData interface used to manipulate form data for use in the XMLHttpRequest API.
- HTTP
- Guides:
- Resources and URIs
- Identifying resources on the Web
- Data URIs
- Introduction to MIME Types
- Complete list of MIME Types
- Choosing between www and non-www URLs
- Basics of HTTP
- Overview of HTTP
- Evolution of HTTP
- HTTP Messages
- A typical HTTP session
- Connection management in HTTP/1.x
- Protocol upgrade mechanism
- Content Security Policy (CSP)
- HTTP Public Key Pinning (HPKP)
- HTTP Strict Transport Security (HSTS)
- Cookie security
- X-Content-Type-Options
- X-Frame-Options
- X-XSS-Protection
- Mozilla web security guidelines
- Mozilla Observatory
- Accept
- Accept-CH
- Accept-CH-Lifetime
- Accept-Charset
- Accept-Encoding
- Accept-Language
- Accept-Patch
- Accept-Ranges
- Access-Control-Allow-Credentials
- Access-Control-Allow-Headers
- Access-Control-Allow-Methods
- Access-Control-Allow-Origin
- Access-Control-Expose-Headers
- Access-Control-Max-Age
- Access-Control-Request-Headers
- Access-Control-Request-Method
- Age
- Allow
- Alt-Svc
- Authorization
- Cache-Control
- Clear-Site-Data
- Connection
- Content-Disposition
- Content-Encoding
- Content-Language
- Content-Length
- Content-Location
- Content-Range
- Content-Security-Policy
- Content-Security-Policy-Report-Only
- Content-Type
- Cookie
- Cookie2
- Cross-Origin-Embedder-Policy
- Cross-Origin-Opener-Policy
- Cross-Origin-Resource-Policy
- DNT
- DPR
- Date
- Device-Memory
- Digest
- ETag
- Early-Data
- Expect
- Expect-CT
- Expires
- Feature-Policy
- Forwarded
- From
- Host
- If-Match
- If-Modified-Since
- If-None-Match
- If-Range
- If-Unmodified-Since
- Index
- Keep-Alive
- Large-Allocation
- Last-Modified
- Link
- Location
- NEL
- Origin
- Pragma
- Proxy-Authenticate
- Proxy-Authorization
- Public-Key-Pins
- Public-Key-Pins-Report-Only
- Range
- Referer
- Referrer-Policy
- Retry-After
- Save-Data
- Sec-Fetch-Dest
- Sec-Fetch-Mode
- Sec-Fetch-Site
- Sec-Fetch-User
- Sec-WebSocket-Accept
- Server
- Server-Timing
- Set-Cookie
- Set-Cookie2
- SourceMap
- Strict-Transport-Security
- TE
- Timing-Allow-Origin
- Tk
- Trailer
- Transfer-Encoding
- Upgrade-Insecure-Requests
- User-Agent
- Vary
- Via
- WWW-Authenticate
- Want-Digest
- Warning
- X-Content-Type-Options
- X-DNS-Prefetch-Control
- X-Forwarded-For
- X-Forwarded-Host
- X-Forwarded-Proto
- X-Frame-Options
- X-XSS-Protection
- CONNECT
- DELETE
- GET
- HEAD
- OPTIONS
- PATCH
- POST
- PUT
- TRACE
- 100 Continue
- 101 Switching Protocols
- 103 Early Hints
- 200 OK
- 201 Created
- 202 Accepted
- 203 Non-Authoritative Information
- 204 No Content
- 205 Reset Content
- 206 Partial Content
- 300 Multiple Choices
- 301 Moved Permanently
- 302 Found
- 303 See Other
- 304 Not Modified
- 307 Temporary Redirect
- 308 Permanent Redirect
- 400 Bad Request
- 401 Unauthorized
- 402 Payment Required
- 403 Forbidden
- 404 Not Found
- 405 Method Not Allowed
- 406 Not Acceptable
- 407 Proxy Authentication Required
- 408 Request Timeout
- 409 Conflict
- 410 Gone
- 411 Length Required
- 412 Precondition Failed
- 413 Payload Too Large
- 414 URI Too Long
- 415 Unsupported Media Type
- 416 Range Not Satisfiable
- 417 Expectation Failed
- 418 I’m a teapot
- 422 Unprocessable Entity
- 425 Too Early
- 426 Upgrade Required
- 428 Precondition Required
- 429 Too Many Requests
- 431 Request Header Fields Too Large
- 451 Unavailable For Legal Reasons
- 500 Internal Server Error
- 501 Not Implemented
- 502 Bad Gateway
- 503 Service Unavailable
- 504 Gateway Timeout
- 505 HTTP Version Not Supported
- 506 Variant Also Negotiates
- 507 Insufficient Storage
- 508 Loop Detected
- 510 Not Extended
- 511 Network Authentication Required
- CSP: base-uri
- CSP: block-all-mixed-content
- CSP: child-src
- CSP: connect-src
- CSP: default-src
- CSP: font-src
- CSP: form-action
- CSP: frame-ancestors
- CSP: frame-src
- CSP: img-src
- CSP: manifest-src
- CSP: media-src
- CSP: navigate-to
- CSP: object-src
- CSP: plugin-types
- CSP: prefetch-src
- CSP: referrer
- CSP: report-to
- CSP: report-uri
- CSP: require-sri-for
- CSP: sandbox
- CSP: script-src
- CSP: script-src-attr
- CSP: script-src-elem
- CSP: style-src
- CSP: style-src-attr
- CSP: style-src-elem
- CSP: trusted-types
- CSP: upgrade-insecure-requests
- CSP: worker-src
- Reason: CORS disabled
- Reason: CORS header ‘Access-Control-Allow-Origin’ does not match ‘xyz’
- Reason: CORS header ‘Access-Control-Allow-Origin’ missing
- Reason: CORS header ‘Origin’ cannot be added
- Reason: CORS preflight channel did not succeed
- Reason: CORS request did not succeed
- Reason: CORS request external redirect not allowed
- Reason: CORS request not HTTP
- Reason: Credential is not supported if the CORS header ‘Access-Control-Allow-Origin’ is ‘*’
- Reason: Did not find method in CORS header ‘Access-Control-Allow-Methods’
- Reason: Multiple CORS header ‘Access-Control-Allow-Origin’ not allowed
- Reason: expected ‘true’ in CORS header ‘Access-Control-Allow-Credentials’
- Reason: invalid token ‘xyz’ in CORS header ‘Access-Control-Allow-Headers’
- Reason: invalid token ‘xyz’ in CORS header ‘Access-Control-Allow-Methods’
- Reason: missing token ‘xyz’ in CORS header ‘Access-Control-Allow-Headers’ from CORS preflight channel
- Feature-Policy: accelerometer
- Feature-Policy: ambient-light-sensor
- Feature-Policy: autoplay
- Feature-Policy: battery
- Feature-Policy: camera
- Feature-Policy: display-capture
- Feature-Policy: document-domain
- Feature-Policy: encrypted-media
- Feature-Policy: fullscreen
- Feature-Policy: geolocation
- Feature-Policy: gyroscope
- Feature-Policy: layout-animations
- Feature-Policy: legacy-image-formats
- Feature-Policy: magnetometer
- Feature-Policy: microphone
- Feature-Policy: midi
- Feature-Policy: oversized-images
- Feature-Policy: payment
- Feature-Policy: picture-in-picture
- Feature-Policy: publickey-credentials-get
- Feature-Policy: screen-wake-lock
- Feature-Policy: sync-xhr
- Feature-Policy: unoptimized-images
- Feature-Policy: unsized-media
- Feature-Policy: usb
- Feature-Policy: vibrate
- Feature-Policy: wake-lock
- Feature-Policy: xr
- Feature-Policy: xr-spatial-tracking
- web-share