CodeIgniter Adding JS & CSS - CodeIgniter

What is CodeIgniter Adding JS & CSS?

Adding JavaScript and CSS (Cascading style Sheet) file in CodeIgniter is quite simple. you have to create JS and CSS folder in root listing and duplicate all of the .js files in JS folder and .css files in CSS folder as shown in the figure.


For example, let us assume, you have created one JavaScript file sample.js and one CSS file style.css. Now, to add these files into your views, load URL helper in your controller as shown below.

After loading the URL helper in controller, simply add the below given lines in the view file, to load the sample.js and style.css file in the view as shown below.


Create a controller called Test.php and save it in application/controller/Test.php

Create a view file called test.php and save it at application/views/test.php

Create a CSS file called style.css and save it at css/style.css

Change the routes.php file in application/config/routes.php to add route for the above controller and add the following line at the end of the file.

Use the following URL in the browser to execute the above example.

All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd Protection Status

CodeIgniter Topics