Media type / text
text/plain
Unstructured human-readable text — the safe default when no more specific type fits, and the type browsers render as-is without interpreting markup.
Served inline: Browsers display this in the tab without granting it script access to the page. Safe to serve inline, provided the bytes really are what the header claims.
Browser behaviour
Renders inertly
Charset
charset required
Compression
Compress in transit
Send it like this
Content-Type: text/plain; charset=utf-8Send `; charset=utf-8`. Without it the receiver falls back to its own default — for some text types that default is us-ascii, and any non-ASCII character then renders wrong.
Handling verdict
Browsers display this in the tab without granting it script access to the page. Safe to serve inline, provided the bytes really are what the header claims.
Send `; charset=utf-8`. Without it the receiver falls back to its own default — for some text types that default is us-ascii, and any non-ASCII character then renders wrong.
The payload is text-like or otherwise repetitive, so gzip or Brotli removes real bytes. Enable it at the server or CDN.
Registered with IANA through a public review process, so the name is stable and every implementation can rely on it meaning the same thing.
Anatomy of the name
RFC 6838Top-level type
text
Text
Subtype
plain
Registered in the standards tree.
Structured syntax
none
No suffix, so the payload format is defined entirely by the subtype itself.
Parameters
charset
Beyond the charset rule above, this type defines no parameters of its own.
What trips people up
2 notes- Serving an untrusted upload as text/plain is the cheap way to neutralise it: the browser shows the source instead of executing it.
- Without a charset the browser guesses, and a UTF-8 document read as windows-1252 renders mojibake.
Response headers
Content-Type: text/plain; charset=utf-8
X-Content-Type-Options: nosniff
Content-Disposition: inline
Vary: Accept-Encodingnosniff stops the browser second-guessing the type you declared, which is what makes the rest of this reliable. Serving it inline is safe here because the browser renders it without granting it script access.
Server configuration
extension mappingnginx
types {
text/plain txt log text conf ini;
}Apache
AddType text/plain .txt .log .text .conf .ini
AddCharset UTF-8 .txt .log .text .conf .iniCaddy
@type path *.txt *.log *.text *.conf *.ini
header @type Content-Type "text/plain; charset=utf-8"