how to load css file in codeigniter

Hi Frnds i cannot able to load css file in codeigniter. so please tell me how to load. Codeigniter sample Directory Structure

  2. models
  3. controllers
  4. assets a) stylesheets b) javascript c) images
  5. Config


    <?php if (!defined('BASEPATH')) exit('No direct script access allowed');
    class Learnersway extends CI_Controller
        function index()



        <link rel="stylesheet" type="text/css" href="assets/stylesheets/main.css"   />

    <div class="wrapper">
    <div class="header">
    <div class="title"><img height="136" src="../images/learnersway.jpg" width="272" /></div>

    <div class="main_menu">


    <div class="main_container">
    <div class="sub_menu">
        <li>HTML Introduction</li>
        <li>HTML Editors</li>
        <li>HTML Basic</li>
        <li>HTML Elements</li>
        <li>HTML Attributes</li>
        <li>HTML Headings</li>
        <li>HTML Paragraphs</li>
        <li>HTML Formatting</li>
        <li>HTML Links</li>
        <li>HTML Head</li>


    <div class="sub_container">
    <div>Under Construction...</div>

    <div class="footer">
    <div class="left">All Rights Reserved @</div>

    <div class="right">
        <li>About Us</li>
        <li>Terms &amp; Privacy Policy</li>



Please tell me how to load css file in codeigniter. Even if can tell me how load javascripts and images also. I am a beginner in codeigniter MVC Framework.

First go to application/config/autoload.php. Then add $autoload['helper'] = array('html','url');

<link rel="stylesheet" href="<?php echo base_url('assets/stylesheets/main.css')?>"/>
<?php echo link_tag('assets/stylesheets/main.css')?>

<?php echo img('asset/images/learnersway.jpg')?>
<img src="<?php echo base_url('asset/images/learnersway.jpg')?>" />

<script src='asset/javascript/yourscript.js'></script>

Please visit userguide

CodeIgniter : Loading CSS and Javascript File, First go to application/config/autoload.php. Then add $autoload['helper'] = array(' html','url'); <link rel="stylesheet" href="<?php echo� The best practice in codeigniter for set up the assets as below flow: application; assets; system; But you want the flow as below: application > assets > css > style.css

There are many ways to include css-files, e.g.:

Load this helper: $this->load->helper('url'); and then you can use this in your view:

<link rel="stylesheet" type="text/css" href="<?php echo base_url(); ?>path/to/css-file">


<link rel="stylesheet" type="text/css" href="<?php echo base_url('path/to/css-file'); ?>">

how to load css file in codeigniter, $this->load->helper('url'); Then add below line to your view file's head tag. Assuming that you have assets/css/ folder is created in your app directory. before using the base_url() you should have to load the URL helper class. To load CSS files by using link_tag () function, we need to load html_helper. CodeIgniter’s html_helper enables the developers to write HTML elements without typing much HTML tags. What you need to do first is, open application/config/autoload.php. Scroll down to helpers section and add html_helper in autoload like I am doing below.

In your view do use site_url(); to load css,js and images as:

<link rel="stylesheet" type="text/css" href="<?php echo site_url();?>assets/stylesheets/main.css"  
<script type="text/javascript" language="javascript" src="<?php echo site_url(); ?>assets/javascript/yourjs.js"></script>

Put this both in head tag and wherever you want to show images use this:

<img title="yourimagetitle"src="<?php echo site_url();?>assets/images/yourimage.extension" height="100" width="200">

How to load css in codeigniter, Load CSS files using link_tag() function � Path of CSS file (href attribute). � ' stylesheet' as rel attribute � 'text/css' value of type attribute � String for the title attribute� I m not sure, but your base_url() is not loading your css file because of index.php in the config. It would likely search for the controller. My way is a clean way, there is nothing wrong with my way, it only matters if you're comfortable using it.

use below lines in your template file

<link rel="stylesheet" href="<?php echo $base?>/application/css/style.css" type="text/css">

and load this helper file $this->load->helper('url')

How to load CSS and JavaScript in CodeIgniter, It is simple to attach/add CSS files using CodeIgniter, if you want to add put into CSS folder, now create your js file named script.js and keep it� Still, Codeigniter 4 is providing now the public folder where you can keep all your images, CSS, js, and other files. So far, you need to create your CSS and js folder and save the files in those folders. Download the Codeigniter 4 version from the official website of Codeigniter 4. Now create a folder named CSS in the public directory, and now create a style.css fine and keep this file in the same folder which you have just created. Now create a js folder in the public directory and once

you can use my answer on this question how to load css, js dynamically in codeigniter

    public function index() { 
// View "css_js_view" Page.
if(your condition){
 $this->data = array( 'css' => site_url()."your css file", //this directory you css 'js' => site_url()."your js file" //this directory you js 
 $this->data = array( 'css' => site_url()."your css file", //this directory you css 'js' => site_url()."your js file" //this directory you js 


than on your view

<!--Load css and js--> 
    <link rel="stylesheet" type="text/css" href="<?php echo $css; ?>">
     <script src="<?php echo $js; ?>"></script>

also you can ue this tutorial How to load css,javascript conditionally?

How to add/attach CSS and JS files in CodeIgniter, autoload['helper'] = array('html','url'); <link rel="stylesheet" src="<?php echo base_url('assets/stylesheets/main.css')?>"/> //OR<?php echo� If you want to create assets folder in your CodeIgniter root directory, then create assets folder in root, open your assets folder and create CSS file named style.css and put into CSS folder, now create your js file called script.js and keep it into js folder.

How to import a CSS file in CodeIgniter PHP, Codeigniter tutorials | Adding CSS and JS files in Codeigniter Our Official Website http://www Duration: 10:08 Posted: Jan 21, 2017 Adding JavaScript and CSS (Cascading Style Sheet) file in CodeIgniter is very simple. You have to create JS and CSS folder in root directory and copy all 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.

Codeigniter tutorials, //To load css files. < link rel = "stylesheet" type = "text/css". href = "<?php echo base_url(); ?>css/style.css">. //To load js files. < script type = 'text/javascript' src� Let us go step by step to understand how to upload files/images in Codeigniter. Steps to Upload Files. Following steps are main steps to upload files in codeigniter-Upload Form(Html View) Controller; Success Page(Html View) Upload Form(Html View) Create a view file as upload_form_view.php in application/views folder. This Html Form contains the

CodeIgniter Adding JS and CSS, The problem I have is how do I access the JS files and CSS files from views that I create? I don't put my JS and CSS in the Views directory. So in this example, I will learn how to display all type messages (alert), in Codeigniter project. we will use toastr for display alert with good layout. toastr provide us any type of alert layout of notification. toastr is open source and easy to use.

  • Hi Boss, if i use echo base_uri() showing empty page. if i use echo base_url() showing content without CSS format. Please tell me now what i need to do. NOTE: i am running codeigniter in my local system
  • Are you sure you loaded url helper? What is your base_url() in config.php file?
  • ya sure i was loaded helper and base_url showing empty like this $config['base_url']= '';
  • it is your folder project
  • I disagree with telling a new user to First go to application/config/autoload.php. Then add $autoload['helper'] = array('html','url'); ... ... ... ... ... ... during learning phase, doing it manually is more meaningful ...
  • I did echo base_url('path/to/css-file'); instead
  • where should i need to load helper file either view or controller. plz tell me.
  • If i use the above code u mentioned. i am getting following error: A PHP Error was encountered Severity: Notice Message: Undefined variable: base Filename: views/home_learnersway.php Line Number: 9 /application/assets/stylesheets/main.css" type="text/css">
  • so instead of $base use your base_url() path.
  • can u tell me how to identify my base_url. Because i am running my source codes in my local system