CodeIgniter Adding JS and CSS

CodeIgniter use Model-View-Controller (MVC) architecture which work on three-tier architecture all the layers is separate file and folder structure. In CodeIgniter  it is recommended that .css and .js file should be placed in CSS and JS folder.

Integrate external css and js file in CodeIgniter, do following steps :
  • Now create assets older in your project root directory .
  • Create css and js folder inside your assets  root directory .
  • Copy your .css file in CSS folder and copy .js file in JS folder.

For base_url() function you must load URL helper in your controller’s constructor Or Autoload 

//Loading url helper

Now you can use base_url() function where link your .css or .js file 

<link rel="stylesheet" type="text/css" href="<?php echo base_url(); ?>assets/css/style.css">
<script type='text/javascript' src="<?php echo base_url(); ?>assets/js/jquery.min.js"></script>

Note : base_url() function print your project base url .In view source it will make complete url. 


Stack Overlode is optimized Tutorials and examples for learning and training. Examples might be simplified to improve reading and learning and understand. Tutorials and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using Stack Overlode, you agree to have read and accepted our terms of use, cookie and privacy policy.