Skip to content

text/css MIME Type — Meaning, Usage & Examples

text/css
Extensions: .css Class: text Spec: RFC 2318 (IANA registered)
View IANA registration ↗

text/css means: text/css is the registered media type for Cascading Style Sheets, the language that describes the presentation of HTML and XML documents. Browsers load stylesheets as text/css and apply their rules to the DOM; the type ensures the file is treated as styling rather than executable script or plain text. 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/css in contexts such as external stylesheets linked from html documents; css served by build pipelines and cdns with long-lived caching; inline style blocks and css-in-js output during development. It is commonly associated with the file extension(s) .css. A stylesheet served with the wrong type (for example text/plain) may be ignored by browsers in standards mode. Always send text/css, set charset=utf-8, and use immutable cache headers for fingerprinted asset filenames.

Advertisement
Ad slot · ref-top

When you'll see text/css

  • External stylesheets linked from HTML documents
  • CSS served by build pipelines and CDNs with long-lived caching
  • Inline style blocks and CSS-in-JS output during development

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

A stylesheet served with the wrong type (for example text/plain) may be ignored by browsers in standards mode. Always send text/css, set charset=utf-8, and use immutable cache headers for fingerprinted asset filenames.

Examples

HTTP
HTTP/1.1 200 OK
Content-Type: text/css; charset=utf-8
Content-Length: 78

body { font-family: system-ui, sans-serif; margin: 0; }
h1 { color: #0f172a; }
curl
curl -i -H "Accept: text/css" https://api.example.com/v1/resource   # inspect the returned Content-Type
JavaScript (fetch)
const res = await fetch("/v1/resource", { headers: { Accept: "text/css" } });
// verify res.headers.get("Content-Type") starts with "text/css"
const text = await res.text();   // handle according to the declared type
Python (requests)
import requests

res = requests.get("https://api.example.com/v1/resource",
                   headers={"Accept": "text/css"}, timeout=10)
res.raise_for_status()
# confirm the server declared the expected type
assert res.headers["Content-Type"].startswith("text/css")
text = res.text   # decode/handle according to the type

Frequently asked questions

Can CSS be served as application/octet-stream?

It will download rather than apply, and browsers may refuse to use it as a stylesheet in strict mode. Serve text/css so the engine parses and applies the rules.

How do I cache CSS efficiently?

Fingerprint the filename (style.abc123.css), send Cache-Control: public, max-age=31536000, immutable, and reference the new name on each deploy so updates bust the cache safely.

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.

Advertisement
Ad slot · ref-in-article

Try the Text Diff

Highlight additions and removals between two texts.

Open tool →