How to import/include a CSS file using PHP code and not HTML code?

You have to surround the CSS with a <style> tag:

<?php include 'header.php'; ?>
<style>
<?php include "https://stackoverflow.com/questions/6315772/CSS/main.css"; ?>
</style>
...

PHP include works fine with .css ending too. In this way you can even use PHP in your CSS file. That can be really helpful to organize e.g. colors as variables.

Leave a Comment