RFC 4180 (October 2005) describes
the format “that seems to be followed by most implementations” and registers
text/csv; it is informational, not a standard every program follows. W3C’s
CSV on the Web recommendations describe the variations. This page follows
RFC 4180,
RFC 7111,
Metadata Vocabulary for Tabular Data
and Model for Tabular Data and
Metadata on the Web, read 2026-11-12.
RFC 4180 grammar
file = [header CRLF] record *(CRLF record) [CRLF]
header = name *(COMMA name)
record = field *(COMMA field)
name = field
field = (escaped / non-escaped)
escaped = DQUOTE *(TEXTDATA / COMMA / CR / LF / 2DQUOTE) DQUOTE
non-escaped = *TEXTDATA
COMMA = %x2C
CR = %x0D
DQUOTE = %x22
LF = %x0A
CRLF = CR LF
TEXTDATA = %x20-21 / %x23-2B / %x2D-7E
- Records end with CR LF; the last one may or may not.
- Every record should have the same number of fields, and the last field must not be followed by a comma.
- A field containing a comma, a double quote or a line break should be in double
quotes; inside quotes a double quote must be written twice:
"say ""hi""". An unquoted field may not contain double quotes. - Spaces are part of a field and should not be ignored.
TEXTDATAallows only printable ASCII. RFC 4180 says common usage is US-ASCII, with other character sets named by thecharsetparameter; the W3C model notes that this restriction “is routinely ignored in practice”.
Media type
text/csv, with optional parameters charset (such as
utf-8) and header (present or
absent). RFC 7111 (January 2014, updates RFC 4180) adds fragment
identifiers for rows, columns and cells, such as #row=5-7,
#col=2 and #cell=4,1 (row 4, column 1); rows and columns
count from 1.
The text/csv registration
From RFC 7111 section 5.1, copied from the RFC 4180 registration with fragment considerations added (read 2026-11-13).
- Parameters: none required.
charset: it should be used, and if absent UTF-8 should be assumed (so US-ASCII CSV works without it); any IANA charset for thetexttree may be named.header:presentorabsent; a user who does not use it decides for themselves. - Encoding: the entity is binary data; line breaks are CRLF as in RFC 2046 section 4.1.1, though some implementations use other values.
- Interoperability: there is no single master specification, so differences among implementations are considerable; be conservative in what you produce and liberal in what you accept. RFC 4180 section 2 is an attempt at a common definition.
- Other fields: no magic number; file extension
CSV; Macintosh file typeTEXT; applications: spreadsheet programs and data conversion utilities; intended usage COMMON; no usage restrictions; authors and contacts Yakov Shafranovich and Erik Wilde; change controller IESG. Security: passive text with no confidentiality or integrity protection, though malicious data may exploit buffer overruns or bugs in a program; and, for fragments, software that supports them behaves differently from software that does not, which can mislead users like spoofing or phishing (see also RFC 3986 and RFC 3987).
Fragment identifiers (RFC 7111)
Three schemes, written lower-case exactly as given: row, col
and cell. Positions count from 1; * means the last row or column.
csv-fragment = rowsel / colsel / cellsel
rowsel = "row=" singlespec 0*( ";" singlespec )
colsel = "col=" singlespec 0*( ";" singlespec )
cellsel = "cell=" cellspec 0*( ";" cellspec )
singlespec = position [ "-" position ]
cellspec = cellrow "," cellcol [ "-" cellrow "," cellcol ]
cellrow = position
cellcol = position
position = number / "*"
number = 1*( DIGIT )
| Fragment | Selects |
|---|---|
#row=4 | The fourth row. #row=5-7 three consecutive rows; #row=5-* row 5 to the last. |
#col=2 | The second column; #col=1-2 the first two; * the last column. |
#cell=4,1 | The field in row 4, column 1. A range gives the upper-left cell, a minus sign and the lower-right cell: #cell=4,1-6,2. |
#row=3;6 | Several selections separated by semicolons; the result may be disjoint, and a user agent decides how to present that. |
Processing rules (section 4):
- A fragment that does not match the syntax must be ignored; clients must not try to correct or guess it, and may report the error.
- A single selection of a row or column beyond the table is ignored.
- A range that extends beyond the table is cut to the actual size.
- An inverse range (
#row=10-5,#cell=10,10-5,5) is ignored. - Each specification is processed independently: an ignored one does not cancel the others. For a 7-row table,
#row=1-2;5-4;13-16selects rows 1 and 2 (the second is inverse, the third out of range). - The parts form one fragment, possibly disjoint or overlapping (
#row=3-6;4-5); whether overlapping parts stay separate is the user agent's decision.
Dialects
W3C’s “Metadata Vocabulary for Tabular Data” (Recommendation, 17 December 2015) defines dialect descriptions, hints that tell a parser how to read a CSV file, with these defaults:
| Property | Default | Meaning |
|---|---|---|
encoding | "utf-8" | Character encoding, one defined in the Encoding specification. |
lineTerminators | ["\r\n", "\n"] | String or array of strings that end a row. |
delimiter | "," | Field separator. |
quoteChar | '"' | Quote character; null also sets the escape character to none. |
doubleQuote | true | If true the escape character is " (quotes doubled); if false it is a backslash. |
header | true | true sets the header row count to 1, false to 0; ignored when headerRowCount is given. |
headerRowCount | 1 | Number of header rows, a non-negative integer. |
skipRows | 0 | Rows to skip at the start of the file, before a header row or data. |
skipColumns | 0 | Columns to skip at the start of each row. |
commentPrefix | "#" | Prefix marking comment lines. |
skipBlankRows | false | Whether blank rows are ignored. |
skipInitialSpace | false | true sets trimming to "start"; ignored when trim is given. |
trim | true in the property list; false in the spec’s own default dialect example | true, false, "true", "false", "start" or "end". |
The two defaults for trim are both in section 5.9 of the
recommendation: the property definition says “The default is true”, while the
default dialect description printed under it has "trim": false. The
“Model for Tabular Data” also gives the trim flag a default of true.
Appendix B of the “Model for Tabular Data and Metadata on the Web” records how some
programs behaved when tested: Excel for Mac 2011 (English locale) saved CSV as
Windows-1252 with LF line endings, quoting only cells that need it and doubling
quotes, and read UTF-8 files as Windows-1252 whether or not a byte order mark was
present; Google Spreadsheets downloaded CSV as UTF-8 without a byte order mark, with
LF line endings. The model also has a text/tab-separated-values response
set the delimiter to tab (see TSV).