devkult_
tools29converters34
home/mime/.txt

.txt MIME type

Plain texttext & code

text/plain

Unformatted text. Also what many servers fall back to for files they don't recognise as binary.

MIME typetext/plain
Extensions.txt
Content-Typetext/plain; charset=utf-8
Compress in transit?Yes — enable gzip or Brotli

Good to know

  • Without charset=utf-8, browsers may guess the encoding and show accented characters as mojibake (é instead of é).
  • A script or stylesheet accidentally served as text/plain is blocked when nosniff is set.

Serve .txt files with the right type

The response header to send:

Content-Type: text/plain; charset=utf-8

Most servers pick the type from the file extension. If yours sends the wrong one, map it explicitly:

nginx (inside the types block in mime.types)
text/plain txt;
Apache (.htaccess or server config)
AddType text/plain .txt
Express
res.set("Content-Type", "text/plain; charset=utf-8");
Python
import mimetypes

mimetypes.add_type("text/plain", ".txt")
HTML file input
<input type="file" accept=".txt,text/plain">

Check it

See what a server sends for a file, and what type a local file really is by its contents:

curl -sI https://example.com/file.txt | grep -i '^content-type:'
file --mime-type file.txt

Frequently asked questions

What is the MIME type for .txt files?

text/plain.

What Content-Type header should a .txt file be served with?

Content-Type: text/plain; charset=utf-8. As a text format, include the charset so browsers don't guess the encoding. It compresses well, so let the server apply gzip or Brotli.

Related types

Headers that go with it: Content-Type · Content-Disposition · X-Content-Type-Options