DevToolsmith

CSV MIME Type

text/csv is the MIME type for comma-separated values (CSV). Here is the Content-Type header to send, the file signature, and how to configure servers and code.

MIME type
text/csv
Extensions
.csv
Content-Type header
text/csv; charset=utf-8
Registered
Yes, with IANA
Compress with gzip
Yes, it is text or uncompressed
Category
Data and text

About CSV files

Registered in RFC 4180, which also describes the format. For exports, send text/csv; charset=utf-8 with Content-Disposition: attachment; filename="export.csv". Excel ignores the charset header and guesses the encoding itself, so add a UTF-8 byte order mark (EF BB BF) at the start of the file if non-English text must open correctly in Excel.

  • In upload forms, accept .csv by extension too: Windows browsers often report CSV files as application/vnd.ms-excel, and some as application/octet-stream.

Other types seen for these files: application/vnd.ms-excel , application/csv , text/x-csv . Accept them when reading uploads, but send text/csv yourself.

File signature

CSV has no fixed signature: it is text without a magic number, so validate uploads by parsing the content rather than by checking bytes.

Serve .csv with the right Content-Type

Response header
Content-Type: text/csv; charset=utf-8
nginx (a line in the types { } block of mime.types)
text/csv csv;
Apache (.htaccess or server config)
AddType text/csv .csv
AddCharset UTF-8 .csv
Caddy
@csv path *.csv
header @csv Content-Type "text/csv; charset=utf-8"
Check what a server sends
curl -sI https://example.com/file.csv | grep -i '^content-type'
# Content-Type: text/csv; charset=utf-8

Set the type in code

Node.js (Express)
res.set('Content-Type', 'text/csv; charset=utf-8');
Python
import mimetypes

mimetypes.add_type('text/csv', '.csv')  # if your system doesn't know it
mimetypes.guess_type('file.csv')[0]  # 'text/csv'
Go
mime.AddExtensionType(".csv", "text/csv; charset=utf-8")
w.Header().Set("Content-Type", "text/csv; charset=utf-8")

Accept .csv uploads

HTML
<input type="file" accept=".csv,text/csv">

The accept attribute only filters the file picker; users can still choose another file. Listing the extension as well as the type matters, because operating systems don’t always report the type you expect.

Related types

  • .tsv (text/tab-separated-values): TSV
  • .xlsx (application/vnd.openxmlformats-officedocument.spreadsheetml.sheet): Excel workbook
  • .json (application/json): JSON

More data and text

.txt , .md , .ndjson , .jsonld , .xml , .yaml , .geojson , .ics , .sql . Look up any extension or type with the MIME type lookup.

Sources

Spotted a mistake? Email hello@devtoolsmith.com and we’ll fix it.

Frequently asked questions

What is the MIME type for .csv files?

text/csv. You may also see application/vnd.ms-excel, application/csv, text/x-csv, which are older or unofficial; send text/csv. It is a text format, so add the character set: "Content-Type: text/csv; charset=utf-8".

Why does my server send the wrong Content-Type for .csv?

Web servers pick the type from the file extension using a table (mime.types in nginx and Apache). If .csv is missing from that table, they send a default such as application/octet-stream or text/plain. Add the mapping as shown on this page, then check the response with "curl -sI".

How can I check that a file really is CSV?

CSV has no fixed file signature, so the extension and content are all you have. Check that the content is what you expect, for example by parsing it, before trusting an upload.