Content-Disposition Header Explained
What the HTTP Content-Disposition header does and when it's used.
Published October 16, 2026
Content-Disposition tells the browser whether to display a response inline or download it as an attachment, and which filename to use.
How it works
It is also used in multipart/form-data parts to name form fields and files.
The Content-Disposition header is part of the HTTP message and is case-insensitive in name.
In a real exchange
curl -i https://example.com/
Content-Disposition: attachment; filename="report.pdf"
Practical examples
The header
Content-Disposition: attachment; filename="report.pdf"Set or use it in code
res.attachment('report.pdf')Inspect it
curl -sI https://example.com | grep -i 'content-disposition'Common mistakes
- Unsafe filenames from user input
- Non-ASCII filenames without filename*
- Header injection through newline characters
Key takeaways
- Content-Disposition: Content-Disposition tells the browser whether to display a response inline or download it as an attachment, and which filename to use.
- Check it in browser DevTools → Network.
- Test with curl -I before deploying.
FAQ
inline vs attachment?
inline displays in the browser; attachment triggers a download.
Is Content-Disposition case sensitive?
Header names are case-insensitive; values may not be.