Introduction
Bootstrap helps you quickly style your website with ready-made designs. Importing it lets you use these styles easily.
Bootstrap helps you quickly style your website with ready-made designs. Importing it lets you use these styles easily.
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-..." crossorigin="anonymous"> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js" integrity="sha384-..." crossorigin="anonymous"></script>
<link> tag inside the <head> to add Bootstrap CSS.<script> tag before the closing </body> to add Bootstrap JavaScript features.<!-- Add Bootstrap CSS --> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<!-- Add Bootstrap CSS and JS --> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet"> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
<!-- Use Bootstrap from npm in a project --> // In your JavaScript or build setup import 'bootstrap/dist/css/bootstrap.min.css'; import 'bootstrap/dist/js/bootstrap.bundle.min.js';
This example shows how to add Bootstrap CSS and JS from a CDN. You see a styled heading and a green button.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>Bootstrap Import Example</title> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-9ndCyUa6mY5h2v+6U6z+6b6b6b6b6b6b6b6b6b6b6b6b6b6b6b6b6b6b6b6b6b6" crossorigin="anonymous"> </head> <body> <div class="container mt-5"> <h1 class="text-primary">Hello, Bootstrap!</h1> <button type="button" class="btn btn-success">Click Me</button> </div> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js" integrity="sha384-ENjdO4Dr2bkBIFxQpeoY9FZ9+6b6b6b6b6b6b6b6b6b6b6b6b6b6b6b6b6b6b6" crossorigin="anonymous"></script> </body> </html>
Always add the CSS link in the <head> so styles load before the page shows.
Put the JavaScript <script> tag just before </body> for faster page loading.
Use the official Bootstrap CDN links to get the latest stable version.
Import Bootstrap CSS with a <link> tag in the <head>.
Add Bootstrap JavaScript with a <script> tag before the closing </body>.
Using Bootstrap helps you build nice, responsive websites quickly.
<head> section to load styles before the page shows.<link> tag is used to include external CSS files like Bootstrap.<script> tag using the src attribute.bootstrap.bundle.min.js and it must be linked with src, not href.<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet"> <title>Bootstrap Test</title> </head> <body> <button class="btn btn-primary">Click Me</button> </body> </html>
<link> tag includes Bootstrap CSS from CDN, so styles apply.btn btn-primary style the button with Bootstrap's primary blue color.<script href="bootstrap.bundle.min.js"></script><script> tag uses src to link files, not href.href means the browser does not load the JavaScript file, so features fail.<link> in the <head> for styles to load early.<script src="..."></script> before closing </body> for proper loading and performance.Pass the test and this pattern moves unknown