How to import a CSS file into a .php file?

PHP

This is how to import (include) a CSS file into a .php file using PHP code.

Example of including a css file with name 'style.css' that's in the parent directory.

<style>
  <?php include 'style.css'; ?>
</style>

Example of including a css file with name 'main.css' that's in a folder named 'build' in the parent directory.

<style>
  <?php include 'build/style.css'; ?>
</style>

Hi I'm Sudheer. I'm a MSc Advanced Computer Science student at Swansea University in Wales, UK. I share my learning resources on this blog. These include notes I created on various topics, step by step guides on how to implement things and documentation of whatever projects I'm working on.

Leave a Comment