Bootstrap5 Installation and Usage
We can install Bootstrap5 in the following two ways:
-
Use the Bootstrap5 CDN.
-
Download Bootstrap 4 from the official getbootstrap.com Download Bootstrap 5.

Bootstrap 5 CDN
CDNJS:
Bootstrap5 CDN
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/5.1.3/css/bootstrap.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/2.11.2/umd/popper.min.js" script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/5.1.3/js/bootstrap.min.js" script>Note:popper.min.js is used for popovers, tooltips, and dropdowns.
bootstrap.bundle.js (uncompressed version) or bootstrap.bundle.min.js (compressed version) includes bundled plugins such as popper.min.js and other dependent scripts, so we can also use the following code directly:
Example
Bootstrap5 CDN(jsDelivr)
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js" crossorigin="anonymous" script>Additionally, you can use the following CDN services:
- Recommended in China 1:https://cdn.bytedance.com/
- Recommended in China 2:https://www.staticfile.net/
- Internationally, it is recommended to use:https://cdnjs.com/
Download Bootstrap 5
You can go to the official https://getbootstrap.com/ Download the Bootstrap5 resource library.
Note:In addition, you can also install via package management tools such as npm, yarn, gem, composer, etc.:
npm install bootstrapyarn add bootstrapgem install bootstrap -v 5.1.1composer require twbs/bootstrap:5.1.1
Creating Your First Bootstrap 5 Page
1. Add the HTML5 doctype
Bootstrap requires the HTML5 file type, so you need to add the HTML5 doctype declaration.
The HTML5 doctype is declared at the head of the document, along with the corresponding encoding:
<!DOCTYPE html><html>
<head>
<meta charset="utf-8" head html>To make websites developed with Bootstrap mobile-friendly and ensure proper rendering and touch zooming, you need to add the viewport meta tag in the head of the web page, as shown below:
width=device-width indicates that the width is the width of the device screen.
initial-scale=1 indicates the initial zoom ratio.
Containers
Bootstrap 5 requires a container element to wrap the website's content.
We can use the following two container classes:
- The .container class is used for containers with fixed width and responsive layout support.
- The .container-fluid class is used for 100% width containers that occupy the full viewport.

Two Bootstrap 5 Pages
Bootstrap5 .container Example
<div class="container">
<h1>My First Bootstrap Page
h1
<
p
This is some text.
p
div
Try it »
The following example shows a container that occupies the full viewport.
Bootstrap5 .container-fluid Example
<div class="container-fluid">
<h1>My First Bootstrap Page
h1
<
p
Uses .container-fluid, a 100% width container that occupies the full viewport.
p
div
Try it »