text/plain means: text/plain is the media type for unformatted human-readable text with no markup interpretation. It is the safest default for displaying arbitrary strings, logs, readme files and simple notes, because browsers render it verbatim without executing scripts or applying styles. Text media types carry human-readable character data. Because they are text, the charset parameter matters: without an explicit charset=utf-8, receivers may guess a legacy encoding and mangle non-ASCII characters. Text types are also the ones browsers render or display inline, so the subtype decides whether content is treated as markup, code, or plain prose. You will encounter text/plain in contexts such as plain-text documents, readme files and license texts; log output, debug dumps and raw error messages; api responses or webhook payloads that are simple strings rather than structured data. It is commonly associated with the file extension(s) .txt. Serving untrusted user content as text/plain is a deliberate XSS mitigation: the browser will not interpret HTML or run scripts. Always add charset=utf-8, and use Content-Disposition: attachment when you want a download rather than inline display.
When you'll see text/plain
- Plain-text documents, README files and license texts
- Log output, debug dumps and raw error messages
- API responses or webhook payloads that are simple strings rather than structured data
How to handle it
When serving a text type, always declare charset=utf-8 unless the specification fixes another encoding, and escape or sanitize content according to how it will be rendered. Treat text/html as executable: never inject untrusted strings into it without encoding. For text/plain and text/csv, preserve line endings and quoting rules so downstream parsers do not split fields incorrectly, and set Content-Disposition when you want a download instead of inline display. As a final checklist for text types: declare charset=utf-8 everywhere, normalize line endings for cross-platform consumers, escape output for the rendering context to prevent injection, and set Content-Disposition deliberately so browsers either display inline or download rather than guessing.
Notes & gotchas
Serving untrusted user content as text/plain is a deliberate XSS mitigation: the browser will not interpret HTML or run scripts. Always add charset=utf-8, and use Content-Disposition: attachment when you want a download rather than inline display.
Examples
HTTP/1.1 200 OK
Content-Type: text/plain; charset=utf-8
Content-Length: 73
Sample text/plain content delivered with the correct Content-Type header. curl -i -H "Accept: text/plain" https://api.example.com/v1/resource # inspect the returned Content-Type const res = await fetch("/v1/resource", { headers: { Accept: "text/plain" } });
// verify res.headers.get("Content-Type") starts with "text/plain"
const text = await res.text(); // handle according to the declared type import requests
res = requests.get("https://api.example.com/v1/resource",
headers={"Accept": "text/plain"}, timeout=10)
res.raise_for_status()
# confirm the server declared the expected type
assert res.headers["Content-Type"].startswith("text/plain")
text = res.text # decode/handle according to the type Frequently asked questions
Is text/plain safe for user-generated content?
Yes — browsers display it verbatim without parsing markup, so it neutralizes HTML/script injection. It is the recommended type when you must echo untrusted strings back to a page.
What charset does text/plain default to?
Historically us-ascii per RFC 2046, so always declare charset=utf-8 explicitly to support international characters correctly.
Do I need to specify charset for text types?
Yes — append ; charset=utf-8 unless the type defines its own encoding rules. Without it, receivers may fall back to a legacy encoding and corrupt non-ASCII characters. UTF-8 is the safe default for the modern web.
What is the difference between text/plain and text/html?
text/plain is displayed verbatim with no markup interpretation; text/html is parsed as a document, executing styles and scripts. Serving user content as text/html when you meant plain text is a cross-site scripting risk.
Why do my non-ASCII characters appear corrupted?
The receiver guessed the wrong encoding because no charset was declared. Send charset=utf-8 in the Content-Type, ensure the bytes are actually UTF-8, and for HTML add a matching meta charset tag.
Try the Text Diff
Highlight additions and removals between two texts.