// mime type · text type

text/csv

Comma-separated values · .csv

What text/csv is

text/csv marks comma-separated values — rows of tabular data. It's what you set when a download should open as a spreadsheet, often alongside a Content-Disposition: attachment header.

How it's used

You'll see this as a Content-Type value on requests and responses — for example Content-Type: text/csv. It's the type associated with the .csv file extension. Text types are human-readable formats. On the web they're assumed to be UTF-8, and browsers can display them directly.

Example

HTTP/1.1 200 OK
Content-Type: text/csv; charset=utf-8
Content-Disposition: attachment; filename="export.csv"

Set text/csv on your server

Node / Express

res.set({
  "Content-Type": "text/csv; charset=utf-8",
  "Content-Disposition": 'attachment; filename="export.csv"',
});

PHP

header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment; filename="export.csv"');

Common problems with text/csv

Excel shows garbled accents in my CSV

Excel often assumes a legacy encoding unless the file starts with a UTF-8 byte order mark (BOM). Writing the three BOM bytes first, or exporting as .xlsx, fixes it.

The CSV downloads instead of opening in a spreadsheet

That is expected with Content-Disposition: attachment. The user's spreadsheet app opens the downloaded file.

What are the formatting rules?

RFC 4180 describes the common format: comma-separated fields, rows ended with CRLF, and fields containing commas, quotes or line breaks wrapped in double quotes, with quotes doubled inside.

Related types

Other text types