Bootstrap 5 Get Started

Set up Bootstrap 5 in your project

🎯 Getting Started with Bootstrap 5

Learn how to include Bootstrap 5 in your web project using CDN or download. Bootstrap can be integrated in minutes, allowing you to start building responsive websites immediately with minimal setup required.


<!-- Basic Bootstrap Template -->
<!DOCTYPE html>
<html>
<head>
    <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
    <h1 class="text-primary">Hello Bootstrap!</h1>
</body>
</html>
                                    

Installation Methods

🌐

CDN Link

The fastest way to get started is using Bootstrap's CDN. Simply add the CSS and JavaScript links to your HTML file and you're ready to use all Bootstrap components instantly.

📦

Download

Download Bootstrap's compiled CSS and JavaScript files from the official website. This method gives you local files that you can customize and use without internet connection required.

💻

Package Manager

Install Bootstrap using npm or yarn for modern development workflows. This method is perfect for projects using build tools like Webpack, Vite, or other bundlers for production.

🎨

Source Files

Download Bootstrap's source Sass files for complete customization control. Compile your own version with custom variables, colors, and components to match your exact design needs.

🔹 Using Bootstrap CDN

The Content Delivery Network (CDN) method is the fastest way to integrate Bootstrap into a project. Simply copy the CSS <link> into your HTML's <head> and the JS bundle <script> just before the closing </body> tag. The CDN delivers Bootstrap files from a global network of servers, often resulting in faster load times due to caching. This method requires no build process or file downloads, making it ideal for quick prototypes, simple websites, or learning environments. However, for production, consider the trade-offs regarding customization and dependency on an external network.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>My Bootstrap Page</title>
    
    <!-- Bootstrap CSS -->
    <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
    
    <div class="container">
        <h1>Hello, Bootstrap!</h1>
        <button class="btn btn-success">Click Me</button>
    </div>

    <!-- Bootstrap JS Bundle -->
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>

🔹 Download Bootstrap

For full control and offline development, download the compiled Bootstrap CSS and JS files directly from the official website. After downloading the ZIP archive, extract it and link to the local bootstrap.min.css and bootstrap.bundle.min.js (which includes Popper) files in your project. This method eliminates reliance on external CDN availability, can improve load times if hosted efficiently, and allows you to easily inspect the source code. It's a straightforward approach suitable for traditional web development workflows where projects are built and deployed with direct file references.

Steps to Download:

  1. Visit getbootstrap.com
  2. Click "Download" button
  3. Extract the ZIP file
  4. Link files in your HTML
<!-- Link to downloaded files -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<script src="js/bootstrap.bundle.min.js"></script>

🔹 Install via npm

For modern development workflows using Node.js and module bundlers like Webpack or Vite, install Bootstrap via npm (or yarn) with the command npm install bootstrap. This method allows you to import Bootstrap's Sass source files into your project, enabling deep customization of variables like colors, spacing, and breakpoints before compilation. You can also import only the specific JavaScript plugins you need, resulting in smaller bundle sizes. This approach integrates seamlessly into build pipelines, supports tree-shaking, and is the recommended method for complex, customizable, and performance-optimized applications.

# Install Bootstrap
npm install [email protected]

# Install Sass (optional, for customization)
npm install sass
// Import Bootstrap in your JavaScript
import 'bootstrap/dist/css/bootstrap.min.css';
import 'bootstrap/dist/js/bootstrap.bundle.min.js';

🔹 Complete Starter Template

Bootstrap provides a verified, production-ready HTML5 starter template that includes all essential meta tags, the responsive viewport tag, Bootstrap's CSS and JS links (via CDN), and a basic structure. Using this template ensures you have the correct HTML5 doctype, character encoding, mobile viewport settings, and proper placement of scripts for optimal rendering and performance. It serves as a flawless foundation, eliminating common setup errors and allowing you to begin developing your layout and components immediately. Always start your Bootstrap projects with this template to guarantee compatibility and best practices from the outset.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Bootstrap 5 Starter</title>
    <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
    
    <nav class="navbar navbar-expand-lg navbar-light bg-light">
        <div class="container">
            <a class="navbar-brand" href="#">My Site</a>
        </div>
    </nav>

    <div class="container mt-5">
        <h1>Welcome to Bootstrap 5</h1>
        <p class="lead">Start building amazing websites!</p>
        <button class="btn btn-primary">Get Started</button>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>

🔹 Important Requirements

Two non-negotiable requirements for Bootstrap 5 are the HTML5 doctype (<!DOCTYPE html>) at the very top of your document and the responsive viewport meta tag (<meta name="viewport" content="width=device-width, initial-scale=1">) inside the <head>. The doctype ensures browsers use modern rendering standards. The viewport tag controls layout on mobile devices, instructing the browser to set the page width to the device's screen width and initial zoom level to 1. Omitting these will cause inconsistent styling, layout issues, and a poor responsive experience.

Required Elements:

  • HTML5 Doctype: <!DOCTYPE html>
  • Viewport Meta: For responsive design
  • UTF-8 Charset: For proper character encoding
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>

🧠 Test Your Knowledge

What is the fastest way to include Bootstrap 5?