I've to add Bootstrap 4 in my custom theme.

I add Bootstrap 3 by using the reference:

How to use bootstrap in my custom theme

But, bootstrap 4 is not working.

  • 1
    What do you mean with "not working" ??
    – Black
    Commented Nov 28, 2019 at 7:26

4 Answers 4


For adding Bootstrap 4 In Magento 2.2.3 (tested) & above in your custom theme follow below steps

1) Bootstrap css files inside web folder

Note: THEME_LOCATION => app\design\frontend\vendor-name\theme-name\


Call bootstrap css files in default_head_blocks


Adding css

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
        <!--Bootstrap css-->
        <css src="css/bootstrap.css" />

2) Adding Js files in bundle form rather then individual because individual doesn't work

Place bootstrap.bundle.js files can download from here


Call Bootstrap Js Into requirejs-config.js


code for

var config = {
    paths: {
    } ,
    shim: {
        'bootstrap': {
            'deps': ['jquery']

Add below code in header.phtml after your already present script tag



<script type="text/javascript">require(['bootstrap']);</script>

Run Below Commands:

php bin/magento setup:static-content:deploy (Append -f if you are using Magento 2.2.x >= version)

php bin/magento cache:flush

Note: Tested on Magento 2.2.3 and Latest as well 2.2.6. Also tested on 2.3.3

Updated : Download Bootstrap compiled from here and use bundle js

  • Ok, Thanks. I will try this solution. BTW What is the difference between bootstrap.bundle.js and bootstrap.js?
    – Magecode
    Commented May 30, 2018 at 13:13
  • Popper.js included in bundle js ..... and jquery is already inside magento.... popper doesn't work alone but it works using as a bundle Commented May 30, 2018 at 15:03
  • 1
    I finally figured it out... I placed the js in MY_THEME/web/js instead of MY_THEME/Magento_Theme/web/js im sorry
    – Black
    Commented Nov 29, 2019 at 11:17
  • 1
    This was the standard working way before 2.2.3 but in 2.2.3 it didn't worked and I discovered the above way. But it stills works in 2.3.2 .... The way you done that's proper way Commented Nov 29, 2019 at 11:20
  • 1
    1000 times thank you :) Commented Jan 22, 2021 at 15:02

You can add Bootstrap this way, follow below steps: Note: This solution doesn't work with Magento 2.2.3 and above

1) Place your JS and CSS at below location



2) Call files in your default_head_blocks.xml


add these line of code

<css src="css/bootstrap.css" />
 <script src="js/bootstrap.min.js"/>

3) Run below commands

php bin/magento setup:upgrade

php bin/magento setup:static-content:deploy
  • And how does it work then with Magento 2.2.3 and above?
    – Black
    Commented Nov 29, 2019 at 11:01
  • Add Vendor_ModuleName::css/bootstrap.css Commented Feb 3, 2023 at 22:09

You should use bower package manager to add bootstrap 4 in your theme web folder.

WHY? Because there are constant update & easy to manage. Run the update command the Bootstrap 4 is updated.

ALSO: We prefer to use LESS or SCSS with bootstrap 4. Its robust and easy to refactor.

Follow below steps to install bower:

1) Install LTS nodeJS on your respective OS from: https://nodejs.org/en/

2) Install bower package manager globally: npm install -g bower

3) Install git from: https://git-scm.com/

4) Install bootstrap 4:

In web directory of you Magento custom theme

For example: Open terminal at <Magento root>/app/design/frontend/MyCustom/theme/web/

Run this command to install bootstrap 4: bower install bootstrap4

5) After this you need to add fonts, bootstrap CSS & bootstrap JS in default layout node to work boostrap on every page in Magento_Theme module in your custom theme.

We use gulp to compile SCSS to CSS.

  • How to use bower package manager?
    – Magecode
    Commented Jun 6, 2018 at 11:17
  • You need to download node from here: link. If you are using linux then use respective package manager. Then install bower using this command: sudo npm install -g bower. After install bower install js/css packages in your Theme directory: app/design/frontend/My/Theme/
    – Ananth
    Commented Jun 7, 2018 at 2:47
  • Here you need to change default install directory from bower_components to web using .bowerrc config file.
    – Ananth
    Commented Jun 7, 2018 at 2:54
  • 1
    I think Bower is not anymore relevant. Bower team even recommends using Yarn or Webpack or Parcel for frontend projects.
    – phagento
    Commented Nov 26, 2018 at 13:06
  • First open package.json file of Bootstrap 4, if you see files array key it shows only that file type matching will be add to your project directory. files key is used by Bower command only. If you want to contribute or recompile Bootstrap then you should try Yarn. Because it will add unnecessary file/directory to the project. Webpack and Parcel are for node project they compile to JavaScript use for frontend.
    – Ananth
    Commented Nov 27, 2018 at 16:39

After reading the above answers, I have another suggestion: put Bootstrap 4 into a module, and use CDN to link the Bootstrap files instead.

I assume you know how to create a basic module. If not, you can refer to here. So here is the steps:

  • Create file app/code/Vendor/Module/view/frontend/layout/default_head_blocks.xml with the following codes:

    <?xml version="1.0"?>
     * Copyright © 2013-2017 Magento, Inc. All rights reserved.
     * See COPYING.txt for license details.
    <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
            <link rel="stylesheet"  type="text/css" src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" integrity="sha384-WskhaSGFgHYWDcbwN70/dfYBj47jz9qbsMId/iRN3ewGhXQFZCSftd1LZCfmhktB" crossorigin="anonymous" src_type="url" />   
            <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous" src_type="url"></script>
            <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous" src_type="url"></script>
            <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js" integrity="sha384-smHYKdLADwkXOn1EmN1qk/HfnUcbVRZyYmZ4qpPea6sjB/pTJ0euyQp0Mk8ck+5T" crossorigin="anonymous" src_type="url"></script>
  • Activate the module and run setup:upgrade command, that's all!


  1. Apply to ALL themes at once, no matter the theme is active or inactive
  2. You don't need to download any files into your system
  3. Very easy to update. Just replace the CDN link is the only task you need to do if needed. You don't need to compile and replace any files when you update to Bootstrap 5, 6, 7...
  4. You can enable and disable Bootstrap with ONE simple command.
  5. You don't need to override anything. Everything is on top of the current codes.
  6. No need to run static deploy which could be time consuming

Tested on Magento 2.2.4, but should work across all Magento 2.X versions. EDIT* changed the link tags href to src to be inline with the devdocs. Reference:

  • CDN can be sometimes slow.
    – phagento
    Commented Nov 26, 2018 at 13:04
  • I get The attribute 'integrity' is not allowed.
    – Black
    Commented Nov 28, 2019 at 10:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.