text/csv CSV Flagship
Identifies comma-separated tabular data, the standard interchange format for spreadsheets and simple datasets.
What it's for
text/csv identifies comma-separated values data — rows of plain text where fields are separated by commas (or occasionally other delimiters, despite the name) and rows by line breaks. It's the lowest-common-denominator tabular data format: every spreadsheet application, database tool, and data pipeline can read and write CSV, making it the default choice for data export/import features where maximum compatibility matters more than rich formatting or type information.
Registered officially in RFC 4180, though real-world CSV files are notoriously inconsistent about following that spec precisely — different delimiter characters, quoting conventions, and line-ending styles are common enough that "CSV" in practice is more of a loose family of similar formats than one strict specification.
Format & syntax
Content-Type: text/csv
Content-Type: text/csv; charset=utf-8
Content-Disposition: attachment; filename="export.csv"
RFC 4180's baseline format: comma-separated fields, rows separated by CRLF line endings, fields containing commas/quotes/newlines wrapped in double quotes (with internal quotes escaped by doubling them: ""). In practice, real-world CSV generators and parsers are often more lenient or use different conventions (semicolon delimiters are common in some European locales due to comma being the decimal separator there, for instance).
How it's used in practice
- Data export features — "export your data as CSV" is a near-universal feature across dashboards, admin panels, and reporting tools, chosen specifically because the recipient can open it directly in Excel, Google Sheets, or any spreadsheet tool without any special software.
- Bulk import/upload flows — many admin interfaces accept CSV uploads for bulk data entry (importing a list of users, products, or records), often paired with a downloadable CSV template showing the expected column structure.
- Data pipeline interchange — CSV remains common as an intermediate format between systems that don't share a database connection or API, precisely because of its simplicity and universal tool support.
- Simple reporting and analytics exports — generating a CSV from query results is often simpler and lighter-weight than generating a full spreadsheet file (like XLSX) when rich formatting isn't needed, just the raw tabular data.
Common mistakes & gotchas
- Excel mangling data on open due to locale/delimiter assumptions — a classic and extremely common CSV headache: Excel's default behavior for opening CSV files depends on system locale settings, and a comma-delimited CSV can get misinterpreted (all data crammed into one column) on a system expecting semicolon delimiters, or numeric-looking strings like leading-zero postal codes or long ID numbers get silently reformatted or truncated.
- Not properly escaping fields containing commas, quotes, or newlines — a field value containing a comma without proper quote-wrapping will be misread as multiple fields, silently corrupting the data structure; using a proper CSV writing library rather than manually joining strings with commas avoids this entirely.
- BOM (byte order mark) handling inconsistencies — some tools (notably Excel on Windows) expect a UTF-8 byte order mark at the start of a CSV file to correctly detect encoding, while other parsers choke on or don't expect one — a frequent source of "special characters look wrong" bugs specifically tied to which tool generated vs. which tool opened the file.
- Assuming CSV has a rigid, universally agreed-upon format — because RFC 4180 exists, it's easy to assume all CSV follows it strictly; in practice, delimiter choice, quoting conventions, and line-ending style vary enough across real-world tools and locales that "just parse it as CSV" can still fail without accounting for these variations, which is why robust CSV parsing libraries handle multiple dialects rather than assuming one strict format.
Comparison & FAQ
| Type | Purpose | Key difference from text/csv |
|---|---|---|
| application/json | Structured, nested data | No native tabular/spreadsheet compatibility, but handles nested/complex structures CSV can't represent |
| application/vnd.ms-excel / OOXML spreadsheet types | Native spreadsheet formats | Support rich formatting, formulas, multiple sheets — CSV is deliberately simpler and format-agnostic |
Why does my CSV file look wrong when opened in Excel?
Most likely a delimiter/locale mismatch — Excel's CSV parsing behavior depends on system locale settings, and comma-delimited files can be misread on systems configured for semicolon-delimited CSV, or vice versa.
Why did Excel strip leading zeros or reformat my numbers?
Excel auto-detects and reformats what it thinks are numbers or dates when opening a CSV, which can strip leading zeros (breaking postal codes, IDs) or reformat numeric-looking strings unexpectedly — explicitly formatting affected columns as text before import, or importing via Excel's "Text Import Wizard" instead of double-clicking to open, avoids this.
Should I add a byte order mark (BOM) to my CSV export?
It depends on your primary consuming tool — Excel on Windows often expects a UTF-8 BOM to correctly detect encoding, while some other parsers don't expect one and may include it as a stray character if not handled. If Excel compatibility with non-ASCII characters is a priority, including a BOM is common practice.
Is text/csv the right type even if my delimiter isn't a comma?
Conventionally yes — despite semicolon-delimited or tab-delimited variants being common in practice (locale differences, or intentionally avoiding comma conflicts), text/csv remains the commonly used MIME type for this general family of delimited tabular text formats.