How To Integrate Bootstrap 4 in Codeigniter
Home » BLOG » Web development » How To Integrate Bootstrap 4 in Codeigniter

How To Integrate Bootstrap 4 in Codeigniter

category:  CodeIgniter, Web development

A couple weeks ago, I wrote a CodeIgniter3 tutorial series. In the series, there is no CSS framework integrating into the application. Today, I will share with you how to integrate one of the popular CSS frameworks which are Bootstrap4 into CodeIgniter.

In my CodeIgniter3 tutorial series, the application looks like this.

Raw Template
figure: Raw Template

The template was created by HTML and CSS only. In this post, we will integrate the Bootstrap 4 framework and turn the plain web page to something likes this.

Template with Bootstrap integrated
figure: Template with Bootstrap integrated

Let’s do this.

What is Bootstrap4 framework

In short, the Bootstrap 4 framework is a pre-built CSS and JavaScript plugins which allows you to use in your projects. It also comes with the responsive grid system, Sass variables and mixins.

CodeIgniter – views folders

For CodeIgniter, it is an MVC pattern application. All the templates must create under the application/views folder.

For the template, I like to separate the header, and footer section and save it into the individual file. To be organized, I will create these sections under the templates folder. Below is an example.

  • application/views folder
    • templates
      • header.php
      • footer.php

All files under the templates folder are global templates. For example, header.php will contain the Navbar menu while footer.php will contain the copyright text. The header.php and footer.php will be includes in every web page. So in your controller, you will load the view files as below.

class News extends CI_Controller

    public function __construct()


    public function index()
        $data['news'] = $this->news_model->get_news();
        $data['title'] = 'News archive';

        // # load the header and fooder templates
        $this->load->view('news/index', $data);

Integrate Bootstrap 4 framework

In order to integrate the Bootstrap framework, we will include the Bootstrap style and scripts (optional) into your templates.

Include the Bootstrap style

We will include the Bootstrap style into your header.php. You can copy the CSS link from here.

<!DOCTYPE html>
<html lang="en">

    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>CodeIgniter | News</title>
    <!-- Bootstrap CSS link -->
    <link rel="stylesheet" href="" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">

Now, your template is ready to use the pre-built Bootstrap style.

Include the Bootstrap scripts – optional

This is an option. If you want to use the JavaScript plugins from Bootstrap. you can simply include the Bootstrap scripts into your footer.php. You can copy the scripts links from here.

<!-- Bootstrap scripts starts -->
<script src="" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
<!-- Bootstrap scripts ends -->


Now, your application already integrated to pre-built JavaScript plugins from Bootstrap framework.

Add Navbar into our page

Let’s try to add a Navbar menu into you page. We will add some pre-built classes from Bootstrap into your Navbar menu as well.

Open your header.php and add following code under body tag.

    <div style="background:#333333;">
        <div class="container">
            <div class="row">
                <div class="col-md-12">
                        <li><a href="<?= base_url('index.php/news') ?>">Home</a></li>
                        <li><a href="<?= base_url('index.php/news/create') ?>">Create</a></li>
                        <li><a href="<?= base_url('index.php/news/reports') ?>">Reports</a></li>

You will notice we have a container class, row class, and col-md-12 class in our Navbar menu. Those are the pre-built classes from Bootstrap. Those classes handle the layout of your web page on all devices (desktop, tablet, and mobile). You can read more about layout classes from Bootstrap here.

And that’s it. It is easy and simple like that.

Bonus – Add some style to make the horizontal menus

From the code above, your Navbar menu will display in a vertical style. To make it a horizontal style, I add my custom style below in the head tag at the header.php.

        ul {
            list-style-type: none;
            margin: 0;
            padding: 0;
            overflow: hidden;
            background-color: #333333;

        li {
            float: left;

        li a {
            display: block;
            color: white;
            text-align: center;
            padding: 16px;
            text-decoration: none;
            transition: all 0.5s;

        li a:hover {
            color: #ffffff;
            text-decoration: none;
            background-color: #777777;

Now your Navbar menu will look the same as mine (figure: Template with Bootstrap integrated).

For more pre-built style, you can visit this link.


The Bootstrap 4 framework will boost your development. The framework comes with pre-built style and JavaScript plugins. Plus, you can customize the style via Sass variables. The framework works well in CodeIgniter. And it also works well with other PHP frameworks and WordPress. I hope you get the idea of how to integrate the Bootstrap framework to your project and enjoy the benefits from this framework.