Skip to Content

Using PHP files to serve CSS

§ ,

Handy tip this. First used it as a way of editing my CSS from with the CMS From Scratch. But I’m looking forward to having dynamically generated CSS files in the future. Probably the most efficient way to get around browser bugs.

Anyhow, to get a PHP file to function as a stylesheet, you need to add the following at the top of the file:

<?php
  header("Content-type: text/css; charset=iso-8859-1");
?>

And then your link tag in your HTML would perhaps look like this:

<link rel="stylesheet" type="text/css" href="styles.php" />

Marvellous. Think about using different background images on different days, or serving different styles to different browsers.