How to use Bootstrap 4 in ASP.NET Core
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
ASP.NET Core does not include Bootstrap by default (since .NET 6+), so you need to add it manually. The three main approaches are: using LibMan (Library Manager) which is built into Visual Studio, installing via npm, or linking from a CDN. LibMan is the simplest for projects that do not use Node.js tooling. Once added, reference Bootstrap's CSS and JS in your layout file, and use Bootstrap classes in your Razor views.
Method 1: LibMan (Recommended for Visual Studio)
LibMan is Microsoft's client-side library manager, built into Visual Studio and available as a CLI tool.
Via Visual Studio UI
- Right-click the project in Solution Explorer
- Select Add > Client-Side Library
- Set provider to
cdnjs - Search for
twitter-bootstraporbootstrap - Select version
4.6.2 - Set target location to
wwwroot/lib/bootstrap/ - Click Install
Via libman.json
Create or edit libman.json in the project root:
Restore via CLI:
Bootstrap 4 requires jQuery and Popper.js for its JavaScript components (dropdowns, modals, tooltips).
Method 2: npm
If your project already uses Node.js:
Then copy the files to wwwroot/lib/ using a build step, or configure your bundler to include them.
Method 3: CDN
Add CDN links directly to your layout file. No local installation needed:
CDN is fastest to set up but requires an internet connection and introduces a third-party dependency.
Setting Up the Layout File
Edit Views/Shared/_Layout.cshtml (MVC) or Pages/Shared/_Layout.cshtml (Razor Pages):
Using Bootstrap in Razor Views
Bootstrap with Tag Helpers
ASP.NET Core Tag Helpers work seamlessly with Bootstrap:
Static Files Configuration
Ensure UseStaticFiles() is configured in Program.cs (or Startup.cs):
Without UseStaticFiles(), the browser cannot load CSS or JS files from wwwroot/.
Common Pitfalls
- Missing jQuery or Popper.js: Bootstrap 4's JavaScript components (modals, dropdowns, tooltips) require jQuery and Popper.js. Without them, these components fail silently.
- Wrong file paths: Files must be in
wwwroot/and referenced with~/. Using~/lib/bootstrap/css/bootstrap.min.cssmaps towwwroot/lib/bootstrap/css/bootstrap.min.css. - Forgetting
UseStaticFiles(): Without this middleware, static files inwwwroot/are not served and CSS/JS returns 404. - Bootstrap 4 vs 5 syntax differences: Bootstrap 5 dropped jQuery and changed
data-toggletodata-bs-toggle. If you copy Bootstrap 5 examples into a Bootstrap 4 project, the JS components will not work. - LibMan not restoring on build: By default, LibMan restores on project open in Visual Studio but not during
dotnet build. Add a build target to restore automatically if deploying via CI.
Summary
- Use LibMan for the simplest Bootstrap 4 setup in Visual Studio projects
- Bootstrap 4 requires jQuery and Popper.js for JavaScript components
- Reference CSS in
<head>and JS before</body>in_Layout.cshtml - Ensure
UseStaticFiles()is in your middleware pipeline - Use
~/prefix for paths to static files inwwwroot/ - ASP.NET Core Tag Helpers (
asp-for,asp-action) combine naturally with Bootstrap CSS classes
Related reading
- How to use C8 IAsyncEnumerableT to async-enumerate tasks run in parallel
- How to use dependency injection with an attribute?
- How to use HttpWebRequest .NET asynchronously?
- How to use HttpWebRequest .NET asynchronously?
- How to use LINQ to select object with minimum or maximum property value
- How to use Microsoft Fakes to Shim Async Task method?
- How to use Reflection to Invoke an Overloaded Method in .NET
- How to use RestSharp with async/await

OOD Fundamentals
Master object-oriented design from first principles, SOLID, design patterns, and classic interview problems with hands-on coding.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.