Bootstrap Setup
Bootstrap can be added to a project in several ways. This lesson covers installing it with npm, referencing the compiled dist files, and organizing your project structure.
Bootstrap Setup Overview
For quick prototypes, linking the compiled CSS and JS from a CDN is enough. For real applications, installing Bootstrap as an npm dependency gives you version control, offline builds, and access to the Sass source for customization.
Once installed, Bootstrap exposes a dist folder with minified CSS and JS bundles, plus a scss folder with the uncompiled source you can import selectively into your own build pipeline.
| Concept | Description | Common Usage |
| npm install bootstrap | Adds Bootstrap and its Popper dependency | Projects using webpack, Vite, or similar bundlers |
| dist/css | Precompiled, minified CSS files | Direct linking without a build step |
| dist/js | Precompiled JS bundles (with/without Popper) | Adding interactive components quickly |
| scss/ source | Uncompiled Sass partials and variables | Customizing colors, spacing, and components |
| Popper.js | Positioning engine for dropdowns, tooltips, popovers | Required by bootstrap.bundle.js |
Bootstrap Setup Example
npm install bootstrap@5.3.3
// main.js (bundler entry point)
import 'bootstrap/dist/css/bootstrap.min.css';
import 'bootstrap/dist/js/bootstrap.bundle.min.js';
// or import the Sass source to customize variables
// @import 'bootstrap/scss/bootstrap';
After installing the package, most bundlers let you import the compiled CSS and JS directly in your entry file. Importing the Sass source instead gives you access to variables and mixins for customization, covered later in the Sass lesson.
Top 10 Bootstrap Setup Examples
These are the setup commands and imports you will reach for most often when installing Bootstrap.
| # | Example | Syntax |
| 1 | Install via npm | npm install bootstrap@5.3.3 |
| 2 | Import compiled CSS | import 'bootstrap/dist/css/bootstrap.min.css'; |
| 3 | Import bundled JS | import 'bootstrap/dist/js/bootstrap.bundle.min.js'; |
| 4 | Import Sass source | @import 'bootstrap/scss/bootstrap'; |
| 5 | Install Popper separately | npm install @popperjs/core |
| 6 | Yarn install | yarn add bootstrap |
| 7 | pnpm install | pnpm add bootstrap |
| 8 | Check installed version | npm list bootstrap |
| 9 | Import only the grid | @import 'bootstrap/scss/grid'; |
| 10 | Import only utilities | @import 'bootstrap/scss/utilities'; |
Popular Real-World Bootstrap Setup Examples
These setup patterns show how teams wire Bootstrap into common project types.
| Scenario | Pattern |
| Vite project entry file | import 'bootstrap/dist/css/bootstrap.min.css';
import 'bootstrap/dist/js/bootstrap.bundle.min.js'; |
| React app root import | // src/main.jsx
import 'bootstrap/dist/css/bootstrap.min.css'; |
| Custom Sass entry point | // custom.scss
$primary: #6f42c1;
@import 'bootstrap/scss/bootstrap'; |
| Static site CDN fallback | <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet"> |
| Excluding Popper for static pages | <script src="dist/js/bootstrap.min.js"></script> |
| Local self-hosted files | <link href="/assets/vendor/bootstrap.min.css" rel="stylesheet"> |
| package.json dependency pin | "bootstrap": "5.3.3" |
| Sass build script | "scripts": { "build:css": "sass custom.scss dist/css/app.css" } |
Best Practices
- Pin an exact Bootstrap version in package.json to avoid unexpected breaking changes.
- Import the bundled JS (bootstrap.bundle.min.js) unless you already manage Popper separately.
- Prefer importing the Sass source when you know you'll need theme customization.
- Keep Bootstrap's CSS import near the top of your global stylesheet chain.
- Use a package manager instead of manually downloading files for easier upgrades.
- Check the changelog before upgrading major or minor versions.
- Only import the Sass partials you need if bundle size matters.
Common Mistakes
- Installing Bootstrap but forgetting to import the CSS anywhere in the app.
- Importing bootstrap.min.js without Popper, then finding dropdowns and tooltips don't position correctly.
- Mixing a CDN-linked Bootstrap version with an npm-installed version in the same project.
- Not pinning the version, leading to silent upgrades that change class behavior.
- Importing the entire Sass source when only a few components are needed.
- Forgetting to reinstall dependencies after cloning a repository that uses Bootstrap.
Key Takeaways
- Bootstrap can be installed via npm, yarn, pnpm, or linked from a CDN.
- The dist folder holds precompiled CSS and JS; the scss folder holds customizable source.
- bootstrap.bundle.min.js includes Popper, required for dropdowns, tooltips, and popovers.
- Sass imports let you customize variables before compiling the framework.
- Pinning versions avoids unexpected breaking changes across a team.
Pro Tip
If you're not customizing themes yet, start with the CDN links to move fast, then migrate to an npm + Sass workflow once you need custom variables.