What is MIME type "text/csv"?

A MIME type is a string that tells browsers and other tools how to handle a particular kind of file.

text/csv denotes files that store data as plain text in a table-like format. Data values are usually separated by commas. This format is common for exchanging structured data between applications.
Files using this MIME type, like CSV, are easy to open in text editors and spreadsheet programs.
This MIME type helps systems recognize the file structure so data can be parsed correctly.

Associated file extensions

Usage Examples

HTTP Header

When serving content with this MIME type, set the Content-Type header:


    Content-Type: text/csv    
  

HTML

In HTML, you can specify the MIME type in various elements:


    <a href="file.dat" type="text/csv">Download file</a>    
  

Server-side (Node.js)

Setting the Content-Type header in Node.js:


    const http = require('http');    
    
    http.createServer((req, res) => {    
      res.setHeader('Content-Type', 'text/csv');    
      res.end('Content here');    
    }).listen(3000);    
  

Associated file extensions

FAQs

Is text/csv the only correct MIME type for CSV files?

Yes, text/csv is the official standard registered with the IANA and defined in RFC 4180. While you might see legacy types like application/csv, application/excel, or application/vnd.ms-excel, you should always use text/csv for modern web development to ensure maximum compatibility with browsers and applications.

How do I fix character encoding issues when serving CSV files?

To prevent special characters (like accents or emojis) from breaking, you must append the charset parameter to the MIME type. Send the header Content-Type: text/csv; charset=utf-8. Without this, browsers and spreadsheet software like Excel might interpret the file using a default encoding (like ASCII or Windows-1252), corrupting the data.

How can I force a CSV file to download instead of opening in the browser?

Because text/csv is a text-based format, many browsers will try to display it directly in the window. To force a file download dialog, you must send the Content-Disposition header from your server: Content-Disposition: attachment; filename="filename.csv".

How do I configure Apache or Nginx to serve .csv files correctly?

For Apache, ensure your .htaccess or config file includes AddType text/csv .csv. For Nginx, verify that your mime.types file includes the line text/csv csv;. If the server is misconfigured, it might serve the file as text/plain or application/octet-stream, causing parsing errors on the client side.

Are there security risks associated with text/csv files?

While CSV files are plain text, they are vulnerable to CSV Injection (or Formula Injection). If a cell starts with characters like =, +, -, or @, spreadsheet software (like Excel or LibreOffice) may execute it as a formula when opened. Always sanitize user input before generating a CSV file to prevent malicious command execution.

Why does Microsoft Excel sometimes fail to open text/csv files correctly from the web?

Excel relies heavily on the Byte Order Mark (BOM) to detect UTF-8 encoding. Even if you send the correct text/csv; charset=utf-8 MIME header, Excel may open the file with garbled characters if the file content does not start with the UTF-8 BOM (\xEF\xBB\xBF). Adding this BOM to the beginning of the file stream usually resolves display issues in Excel.

General FAQ

What is a MIME type?

A MIME (Multipurpose Internet Mail Extensions) type is a standard that indicates the nature and format of a document, file, or assortment of bytes. MIME types are defined and standardized in IETF's RFC 6838.

MIME types are important because they help browsers and servers understand how to process a file. When a browser receives a file from a server, it uses the MIME type to determine how to display or handle the content, whether it's an image to display, a PDF to open in a viewer, or a video to play.

MIME types consist of a type and a subtype, separated by a slash (e.g., text/html, image/jpeg, application/pdf). Some MIME types also include optional parameters.

How do I find the MIME type for a file?

You can check the file extension or use a file identification tool such as file --mime-type on the command line. Many programming languages also provide libraries to detect MIME types.

Why are multiple MIME types listed for one extension?

Different applications and historical conventions may use alternative MIME identifiers for the same kind of file. Showing them all helps ensure compatibility across systems.