DevToolsmith

MD MIME Type

text/markdown is the MIME type for Markdown documents. Here is the Content-Type header to send, the file signature, and how to configure servers and code.

MIME type
text/markdown
Extensions
.md, .markdown
Content-Type header
text/markdown; charset=utf-8
Registered
Yes, with IANA
Compress with gzip
Yes, it is text or uncompressed
Category
Data and text

About Markdown files

Registered in RFC 7763, with an optional variant parameter such as text/markdown; charset=utf-8; variant=GFM. Browsers show Markdown as plain text, they don’t render it; servers that don’t know the extension may send application/octet-stream, which makes the file download instead.

Other types seen for these files: text/x-markdown . Accept them when reading uploads, but send text/markdown yourself.

File signature

MD has no fixed signature: it is text without a magic number, so validate uploads by parsing the content rather than by checking bytes.

Serve .md with the right Content-Type

Response header
Content-Type: text/markdown; charset=utf-8
nginx (a line in the types { } block of mime.types)
text/markdown md markdown;
Apache (.htaccess or server config)
AddType text/markdown .md .markdown
AddCharset UTF-8 .md .markdown
Caddy
@md path *.md *.markdown
header @md Content-Type "text/markdown; charset=utf-8"
Check what a server sends
curl -sI https://example.com/file.md | grep -i '^content-type'
# Content-Type: text/markdown; charset=utf-8

Set the type in code

Node.js (Express)
res.set('Content-Type', 'text/markdown; charset=utf-8');
Python
import mimetypes

mimetypes.add_type('text/markdown', '.md')  # if your system doesn't know it
mimetypes.guess_type('file.md')[0]  # 'text/markdown'
Go
mime.AddExtensionType(".md", "text/markdown; charset=utf-8")
w.Header().Set("Content-Type", "text/markdown; charset=utf-8")

Accept .md uploads

HTML
<input type="file" accept=".md,.markdown,text/markdown">

The accept attribute only filters the file picker; users can still choose another file. Listing the extension as well as the type matters, because operating systems don’t always report the type you expect.

Related types

  • .txt (text/plain): Plain text
  • .html (text/html): HTML
  • .yaml (application/yaml): YAML

More data and text

.csv , .tsv , .json , .ndjson , .jsonld , .xml , .geojson , .ics , .sql . Look up any extension or type with the MIME type lookup.

Sources

Spotted a mistake? Email hello@devtoolsmith.com and we’ll fix it.

Frequently asked questions

What is the MIME type for .md files?

text/markdown. You may also see text/x-markdown, which is older or unofficial; send text/markdown. It is a text format, so add the character set: "Content-Type: text/markdown; charset=utf-8".

Why does my server send the wrong Content-Type for .md?

Web servers pick the type from the file extension using a table (mime.types in nginx and Apache). If .md is missing from that table, they send a default such as application/octet-stream or text/plain. Add the mapping as shown on this page, then check the response with "curl -sI".

How can I check that a file really is MD?

MD has no fixed file signature, so the extension and content are all you have. Check that the content is what you expect, for example by parsing it, before trusting an upload.