header("Content-type: text/css"); is working in Firefox and Chrome, but in Internet Explorer 9 it shows up as 'text/html'

header("Content-type: text/css"); is working in Firefox and Chrome, but in Internet Explorer 9 it shows up as 'text/html'

  1. Blog
  2. 15 November 2026
  3. 4 min read

Stefan Bogdanescu

Founder & Senior Architect

The Hidden Negotiation: Why IE9 Rejects PHP-Served CSS

You might assume that if a file is requested as text/css by a browser, it should render correctly regardless of how the server delivers it. However, when serving stylesheets through a PHP file like style.css.php, Internet Explorer 9 behaves differently than Chrome or Firefox. While modern browsers accept the response and apply the styles, IE9 returns a 406 Not Acceptable error and attempts to download the file as if it were an HTML document.

This discrepancy isn't a bug in IE9's rendering engine; it is a result of how the server handles content negotiation.

The Root Cause: Content Negotiation Failures

The core issue lies in the Vary header and the server's logic for detecting the browser. When you access style.css.php, the PHP script likely runs logic to determine what type of response to send based on the Accept header sent by the client.

In your specific case, the request headers show that IE9 is sending Accept: text/css. A well-configured server should interpret this and return a file with a Content-Type: text/css header. Instead, the server responds with 406 Not Acceptable and a Content-Type: text/html; charset=iso-8859-1.

The presence of the Vary: negotiate header confirms that the server is attempting content negotiation. It is checking the incoming request to see if it can serve the requested resource in a format the client understands. In modern browsers like Chrome and Firefox, this negotiation succeeds because they explicitly signal support for CSS, and the server responds accordingly. IE9, however, triggers a different code path on the server side that fails to recognize the request as valid for a CSS file, resulting in an HTML response being sent instead.

Why IE9 Tries to Download the File

When you open the URL style.css.php directly in a new tab within IE9, it attempts to download the file rather than rendering it inline. This happens because the browser receives a text/html content type from the server. Browsers treat files served with text/html as downloadable resources or pages to be navigated to, not as external stylesheets to be injected into the DOM.

The <link> tag in your HTML head:

<link rel="stylesheet" type="text/css" href="/assets/css/style.css.php" media="screen" />

correctly specifies that you expect a CSS file. However, because the server responds with 406 and text/html, the browser ignores the rel="stylesheet" instruction. The Network tab in IE9's F12 tools will show a red exclamation mark next to the request, indicating the negotiation failed and the resource was not accepted by the client.

Resolving the Negotiation Conflict

To fix this, you must ensure that the server always returns text/css for requests targeting your PHP-generated stylesheets, regardless of the user agent. There are two primary approaches to resolving this without breaking compatibility with other browsers.

1. Enforce Static MIME Types in PHP

The most robust solution is to modify the PHP file itself (or a middleware layer wrapping it) to bypass content negotiation logic that relies on the User-Agent string for IE9. Instead of guessing the browser, force the response header immediately:

<?php
// Inside style.css.php
header('Content-Type: text/css; charset=utf-8');
?>
/* Your CSS styles */
body { color: black; }

By explicitly setting the Content-Type header before any output or negotiation logic runs, you override the server's attempt to serve HTML. This ensures that even if the server's negotiation logic misinterprets IE9, the explicit header takes precedence. Note that standard HTTP headers should be sent before any HTML or whitespace is echoed.

2. Serve Static Files Instead

A common architectural pattern that avoids this issue entirely is to generate the CSS file once and save it as a static .css file. The PHP logic can then simply read and output the contents of that file without executing negotiation code for every request. This eliminates the Vary: negotiate header dependency and ensures consistent behavior across all browsers, including legacy versions like IE9.

Trade-offs and Considerations

While fixing the header resolves the immediate error, you should consider the implications of content negotiation. If your PHP script relies on detecting the User-Agent to serve different styles (e.g., mobile vs. desktop), you risk fragmenting your CSS delivery. Relying on Accept headers for content negotiation in CSS is generally discouraged because it adds unnecessary complexity and can lead to exactly the kind of browser-specific issues seen with IE9.

If you are using a framework like Laravel, you might consider leveraging built-in asset management or ensuring that your application's entry point explicitly sets global response headers if dynamic negotiation is unavoidable. However, the safest path forward remains explicit header enforcement in the specific PHP file handling the CSS generation.

Ultimately, the goal is to treat CSS files as static assets regardless of how they are generated on the server. By forcing the Content-Type: text/css header, you align your application's behavior with HTTP standards and eliminate the friction that causes IE9 to reject the stylesheet.

Our network