DevKits

Content · Response header

Content-Disposition

Controls whether a resource is displayed inline or triggered as a download.

What is Content-Disposition?

The Content-Disposition response header tells the browser how to present the resource. `inline` (the default) tries to render it in the page; `attachment` forces a download prompt and uses the supplied filename as the suggested save name. In short: to make a browser download a file instead of opening it, send `Content-Disposition: attachment`. It can also be used on multipart/form-data body parts to name a form field, but its most common meaning in an HTTP response is 'open inline vs force download'.

Typical usage

Set on responses that should be downloaded rather than opened in the browser. In HTML there is no attribute that sets it — you must send the header from the server (the <a download> attribute is the client-side equivalent for same-origin links).

Examples

Force download (attachment)

Content-Disposition: attachment; filename="report.pdf"

Open inline in the browser

Content-Disposition: inline; filename="preview.pdf"

Filename containing a comma — must be quoted

Content-Disposition: attachment; filename="Smith, John - invoice.pdf"

Non-ASCII / UTF-8 filename

Content-Disposition: attachment; filename*=UTF-8''%E6%8A%A5%E5%91%8A.pdf

S3 / CDN presigned URL override (query param)

https://bucket.s3.amazonaws.com/key?response-content-disposition=attachment%3B%20filename%3D%22report.pdf%22

Common gotchas

1) `inline` means 'display in the browser if it can', `attachment` means 'always download' — that is the core meaning most people search for. 2) For non-ASCII filenames, use `filename*` with UTF-8 percent-encoding (RFC 5987); legacy `filename=` may show mojibake in older browsers. 3) There is no way to set Content-Disposition purely from HTML — it is a server-sent response header; the closest HTML-only option is the <a download> attribute, which only works for same-origin URLs. 4) Even with `attachment`, a browser that cannot determine a safe filename may still display certain types inline. 5) If the filename contains a comma, space, semicolon, or any special character, it MUST be wrapped in double quotes — `filename=Smith, John.pdf` is parsed as two parameters and breaks; write `filename="Smith, John.pdf"`. 6) Object stores like Amazon S3 let you override the header per-request via the `response-content-disposition` query parameter on a presigned URL (e.g. `?response-content-disposition=inline%3B%20filename%3D...`) — the whole header value must be URL-encoded. This is how you force a browser to download (or preview inline) a file straight from a presigned S3/CDN link without re-uploading it.

Also known as

Also commonly written as: content disposition · content-disposition header · content disposition header · content disposition attachment · content disposition filename · content-disposition attachment filename · content disposition inline · content disposition meaning · disposition meaning in http response · content disposition header forces download · how to set content disposition header in html · content-disposition attachment download browser · inline vs attachment · content disposition handle filenames with commas · content-disposition filename with comma · response-content-disposition · response-content-disposition=inline filename · s3 response-content-disposition presigned url · force download link browser instead of opening. These variants — including plural forms, unhyphenated spellings, and Japanese (ヘッダ) — all refer to the same Content-Disposition HTTP header.

Specification

RFC 6266

Frequently asked questions

What is the Content-Disposition HTTP header?

The Content-Disposition response header tells the browser how to present the resource. `inline` (the default) tries to render it in the page; `attachment` forces a download prompt and uses the supplied filename as the suggested save name. In short: to make a browser download a file instead of opening it, send `Content-Disposition: attachment`. It can also be used on multipart/form-data body parts to name a form field, but its most common meaning in an HTTP response is 'open inline vs force download'.

Is Content-Disposition a request or response header?

Content-Disposition is a response header — the server sends it to the client. Set on responses that should be downloaded rather than opened in the browser. In HTML there is no attribute that sets it — you must send the header from the server (the <a download> attribute is the client-side equivalent for same-origin links).

What does a Content-Disposition header look like?

A typical Content-Disposition header looks like: Content-Disposition: attachment; filename="report.pdf" (Force download (attachment)).

What are common mistakes with Content-Disposition?

1) `inline` means 'display in the browser if it can', `attachment` means 'always download' — that is the core meaning most people search for. 2) For non-ASCII filenames, use `filename*` with UTF-8 percent-encoding (RFC 5987); legacy `filename=` may show mojibake in older browsers. 3) There is no way to set Content-Disposition purely from HTML — it is a server-sent response header; the closest HTML-only option is the <a download> attribute, which only works for same-origin URLs. 4) Even with `attachment`, a browser that cannot determine a safe filename may still display certain types inline. 5) If the filename contains a comma, space, semicolon, or any special character, it MUST be wrapped in double quotes — `filename=Smith, John.pdf` is parsed as two parameters and breaks; write `filename="Smith, John.pdf"`. 6) Object stores like Amazon S3 let you override the header per-request via the `response-content-disposition` query parameter on a presigned URL (e.g. `?response-content-disposition=inline%3B%20filename%3D...`) — the whole header value must be URL-encoded. This is how you force a browser to download (or preview inline) a file straight from a presigned S3/CDN link without re-uploading it.

Related headers

Work with this header