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

Bootstrap 4 CDN
In China, it is recommended to use the ByteDance static resource public library:
Bootstrap4 CDN
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.6.1/css/bootstrap.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js" script>
<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/4.6.1/js/bootstrap.min.js" script>In China, it is recommended to use libraries on Staticfile CDN:
Bootstrap4 CDN
<link rel="stylesheet" href="https://cdn.staticfile.net/twitter-bootstrap/4.3.1/css/bootstrap.min.css">
<script src="https://cdn.staticfile.net/jquery/3.2.1/jquery.min.js" script>
<script src="https://cdn.staticfile.net/popper.js/1.15.0/umd/popper.min.js" script>
<script src="https://cdn.staticfile.net/twitter-bootstrap/4.3.1/js/bootstrap.min.js" script>Note:popper.min.js is used for popovers, tooltips and dropdowns; currently bootstrap.bundle.min.js already includes popper.min.js。
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 4
You can go to the official https://getbootstrap.com/ website to download the Bootstrap4 resource library.
Note:In addition, you can also install via package management tools such as npm, gem, composer, etc.:
npm install bootstrap@4.0.0-beta.2
gem 'bootstrap', '~> 4.0.0.beta2' composer require twbs/bootstrap:4.0.0-beta.2
Creating Your First Bootstrap 4 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.
shrink-to-fit=no automatically adapts to the width of mobile screens.
Containers
Bootstrap 4 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 4 Pages
Bootstrap4 .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.
Bootstrap4 .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 »