A2oz

How to Download Bootstrap in React?

Published in Web Development 1 min read

You don't need to download Bootstrap directly when using it with React. Instead, you can easily include it in your project using a Content Delivery Network (CDN) or a package manager.

Using a CDN

  1. Add the Bootstrap CSS link to your index.html file:

    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" 
          integrity="sha384-xOolHFLEhcuI7mLiXc11tP7/OzK+9oWPnSs+w/8+f1z54sN0X+b/RB4/G8f" 
          crossorigin="anonymous">
  2. Include the Bootstrap JavaScript file (optional):

    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.slim.min.js" 
            integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" 
            crossorigin="anonymous"></script>
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js" 
            integrity="sha384-9/reFTGAW83EW2RDu2S0VKaIzap3H66lZH81PoYlFhbGU+6BZp+G7niu735Sk7lN" 
            crossorigin="anonymous"></script>
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js" 
            integrity="sha384-+sLIOodYlgK+8aW/bn7BL7wG3d3YKb+lI4tKyiCw/kgp/g43IA8Q+mGNvNUb" 
            crossorigin="anonymous"></script>

Using a Package Manager (npm or yarn)

  1. Install Bootstrap using your package manager:

    npm install bootstrap

    or

    yarn add bootstrap
  2. Import Bootstrap in your React component:

    import 'bootstrap/dist/css/bootstrap.min.css'; 

    Note: You might need to adjust the import path depending on the structure of your project.

Using a React Component Library

You can also utilize React component libraries that offer pre-built components with Bootstrap styling. Popular examples include:

These libraries provide a convenient way to use Bootstrap in React without directly managing CSS or JavaScript.

Related Articles