Skip to main content

Content-Disposition

ResponseActive

Content-Disposition controls whether a response is displayed inline in the browser or downloaded as a file attachment. 'inline' (default) renders the content. 'attachment; filename="file.pdf"' triggers a download prompt. This is the header behind every browser file download – including API endpoints that export CSV, PDF, or ZIP files.

Content-Disposition: inline | attachment[; filename="<name>"][; filename*=UTF-8''<encoded-name>]

Description

Content-Disposition was originally defined for MIME email (RFC 2183) and adapted for HTTP (RFC 6266). In HTTP responses, 'attachment' causes the browser to download rather than render the response. The filename parameter provides the suggested save name. The filename* parameter (RFC 5987 encoding) supports non-ASCII filenames. Security: always sanitize the filename value – path traversal characters (../) in filename can cause issues on older clients.

Directives

DirectiveDescription
inlineDefault. Browser renders the content in the viewport.
attachmentBrowser downloads the content as a file.
filenameSuggested filename for the download. ASCII only.
filename*RFC 5987 encoded filename. Supports Unicode filenames.

Examples

Force download
http
HTTP/1.1 200 OK
Content-Type: application/pdf
Content-Disposition: attachment; filename="report-2025.pdf"
Unicode filename
http
Content-Disposition: attachment; filename*=UTF-8''%E5%A0%B1%E5%91%8A.pdf
Inline display
http
Content-Disposition: inline

Related

Specification

RFC 6266Content-Disposition specification →