---
source: https://iinventedlight.com/library/notes/go-encoding-csv.md
title: "encoding/csv: read and write RFC 4180 CSV files"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "BSD-3-Clause (Go); BSD-3-Clause (Go); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "Summary by iinventedlight (AI-assisted). Sources: Go, encoding/csv package reference; Go, encoding/csv/reader.go source. BSD-3-Clause (https://go.dev/LICENSE). Copyright The Go Authors."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-23
status: published
approved_by: "Cole Withington, 2026-11-27 14:30 PT: \"Yes, publish all of that now\""
checked_on: 2026-11-23
as_of: 2026-11-23
confidence: medium
untested: "Not reproduced (2026-11-23). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: coding-references
topic_area: "code-systems: go-encoding-csv"
tags: [go, csv, encoding, files]
client: Librarian
sources:
  - id: S1
    title: "encoding/csv package reference"
    publisher: Go
    url: https://pkg.go.dev/encoding/csv
    accessed: 2026-11-23
    license: "BSD-3-Clause"
  - id: S2
    title: "encoding/csv/reader.go source"
    publisher: Go
    url: https://go.dev/src/encoding/csv/reader.go
    accessed: 2026-11-23
    license: "BSD-3-Clause"
---
# encoding/csv: read and write RFC 4180 CSV files
**Answer:** Package csv reads and writes comma-separated values files. The supported layout follows RFC 4180, with one documented default: Writer emits LF rather than CRLF. Newlines and commas may be included in a quoted-field.

## The format the package accepts

Package csv reads and writes comma-separated values (CSV) files.

CSV files come in many kinds. This package follows RFC 4180, except that Writer uses LF instead of CRLF as its default newline.

A csv file contains zero or more records of one or more fields per record.

A newline character separates each record. The final record may optionally be followed by a newline character.

## Whitespace, blanks, and quotes

White space is considered part of a field.

A carriage return sitting just before a newline is silently removed.

Blank lines are ignored, but a line that contains only whitespace (apart from its ending newline) is not treated as blank.

A quoted-field starts and ends with a quote character, and those surrounding quotes are not part of the field.

A second quote character inside a quoted-field is considered a single quote. Newlines and commas may be included in a quoted-field.

## What the source comments repeat

The package supports the format described in RFC 4180.

Blank lines are ignored.

## See also

- [go-encoding-json](https://iinventedlight.com/library/notes/go-encoding-json/)
- [go-bufio](https://iinventedlight.com/library/notes/go-bufio/)

## Claims

- id: C1
  claim: The csv package reads and writes comma-separated values files.
  source: S1
  evidence: "Package csv reads and writes comma-separated values"

- id: C2
  claim: The supported format is RFC 4180, except Writer defaults to LF.
  source: S1
  evidence: "supports the format described in RFC 4180"

- id: C3
  claim: Writer uses LF instead of CRLF by default.
  source: S1
  evidence: "Writer uses LF instead of CRLF as newline character by default"

- id: C4
  claim: White space is considered part of a field.
  source: S1
  evidence: "White space is considered part of a field"

- id: C5
  claim: The source comments also describe RFC 4180 support.
  source: S2
  evidence: "described in RFC 4180"

- id: C6
  claim: The source comments say blank lines are ignored.
  source: S2
  evidence: "Blank lines are ignored"

## Sources

- [S1] encoding/csv package reference. Go. https://pkg.go.dev/encoding/csv . License: BSD-3-Clause. Accessed 2026-11-23.

- [S2] encoding/csv/reader.go source. Go. https://go.dev/src/encoding/csv/reader.go . License: BSD-3-Clause. Accessed 2026-11-23.

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Go, encoding/csv package reference; Go, encoding/csv/reader.go source. BSD-3-Clause (https://go.dev/LICENSE). Copyright The Go Authors. Text was condensed and changed from the originals.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
