How to use bootstrap 4 in Laravel 5.4?
Stefan Bogdanescu
Founder & Senior Architect · 2026-06-29
# How to Use Bootstrap 4 in Laravel 5.4: Debunking the NPM Installation Confusion
As a senior developer working with the Laravel ecosystem, we often run into integration hurdles when mixing backend frameworks with frontend libraries. The situation you've describedâinstalling Bootstrap via npm but seeing Bootstrap 3 behaviorâis extremely common. It usually points not to an error in the installation itself, but rather a missing step in the asset compilation and linking process specific to how Laravel handles front-end assets.
This post will walk you through exactly what needs to happen to ensure Bootstrap 4 is correctly deployed and utilized within your Laravel 5.4 application, focusing on best practices for modern asset management.
## Understanding the NPM vs. Compilation Disconnect
When you run `npm install bootstrap@4.0.0-alpha.6`, you are installing the source files of Bootstrap into your project's `node_modules` directory. This is excellent for development and allows you to use SASS variables or customize the theme locally. However, simply placing those files in your project folder does *not* automatically inject the resulting CSS into your Laravel view.
Laravel relies on a front-end build process (historically using Laravel Mix or Vite) to compile source files (like Sass/SCSS) into the final, optimized CSS and JavaScript assets that the browser actually requests. If these compilation steps are missing or misconfigured, you end up with either no styles or stale, uncompiled files.
## The Correct Way: Integrating Bootstrap via Assets Pipeline
The professional approach in a structured framework like Laravel is to treat the framework as a dependency managed by your build system, not just a collection of static files. You should integrate Bootstrap by compiling its source files through your existing asset pipeline.
### Step 1: Set up SCSS and Dependencies
Ensure you have a working setup for compiling Sass. If you are using Laravel Mix (common in older Laravel versions like 5.4), you would typically configure it to process your custom styles.
In your main stylesheet, instead of manually linking the raw Bootstrap CSS files, you should import the necessary Bootstrap mixins or variables into your primary SCSS file:
```scss
// assets/sass/app.scss
// Import Bootstrap 4 source files using the @import directive
@import "~bootstrap/scss/bootstrap";
// Now you can customize variables and add your own styles on top
body {
background-color: #f8f9fa;
}
```
### Step 2: Ensure Compilation Runs
The crucial step is ensuring that when you run your asset compilation command (e.g., `npm run dev` or `npm run watch`), the build process correctly processes this imported file and outputs the final, working CSS files into your public directory. If you are following Laravel best practices for managing assets, this entire workflow should be managed by your framework setup. For robust front-end scaffolding in a Laravel project, understanding these asset pipelines is key to maintaining clean code, much like how we approach dependency management in large applications on platforms like [laravelcompany.com](https://laravelcompany.com).
## Alternative: The Quick Fix (CDN)
If you are just prototyping or need a very quick setup without setting up the full asset compilation pipeline immediately, the simplest method is to bypass local NPM installation and use a Content Delivery Network (CDN) link directly in your main Blade layout file. This eliminates the need for complex local compilation:
```html
```
While this is faster, remember that for a production-grade Laravel application, relying solely on CDNs limits your control over caching, versioning, and performance optimization. Sticking to the asset compilation method ensures your entire stack remains cohesive and maintainable.
## Conclusion
The confusion between installing a library via npm and actually using its compiled output is a classic front-end integration problem. To successfully use Bootstrap 4 in Laravel 5.4, you must bridge the gap between the local source files (NPM) and the public assets served by the framework (Blade views). The recommended path involves leveraging your existing asset pipeline to compile the Bootstrap SCSS correctly, ensuring that what gets deployed is the intended Bootstrap 4 functionality, leading to a more stable and scalable application.