BootStrap

3 min read
What is Bootstrap?
Bootstrap is a free and open-source CSS framework.
Used to build responsive and mobile-first websites quickly.
Provides pre-styled components, layout grid, and utility classes.
Getting Started with Bootstrap 5.3
Using CDN:
<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>
Starter Template:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Bootstrap Page</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet" />
</head>
<body>
<h1 class="text-center mt-4">Hello Bootstrap!</h1>
</body>
</html>
Layout System (Grid in Bootstrap)
Bootstrap uses a 12-column grid system.
Based on Flexbox.
๐น Containers:
<div class="container">Standard Width</div>
<div class="container-fluid">Full Width</div>
๐น Rows & Columns:
<div class="container">
<div class="row">
<div class="col-4">Column 1</div>
<div class="col-4">Column 2</div>
<div class="col-4">Column 3</div>
</div>
</div>
Bootstrap 5.3 Breakpoints
Bootstrap uses breakpoints to make websites responsive โ so they look good on all screen sizes.
Device Size | Class Infix | Screen Width |
๐ฑ Extra Small | (none) | Less than 576px |
๐ฑ Small | sm | 576px and up |
๐ฑ๐ฑ Medium | md | 768px and up |
๐ป Large | lg | 992px and up |
๐ฅ๏ธ Extra Large | xl | 1200px and up |
๐ฅ๏ธ๐บ Extra Extra Large | xxl | 1400px and up |
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.7/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-LN+7fdVzj6u52u30Kp6M/trliBMCMKTyK833zpbD+pXdCLuTusPj697FH4R/5mcr" crossorigin="anonymous">
<style>
*{
padding: 0;
margin: 0;
box-sizing: border-box;
}
.box {
background-color: lightblue;
padding: 20px;
text-align: center;
border: 2px dashed #007bff;
margin-bottom: 20px;
}
</style>
</head>
<body>
<!-- Normal Container: fixed width based on screen size -->
<div class="container">
<div class="box">.container (Fixed Width)</div>
</div>
<!-- Fluid Container: always 100% width -->
<div class="container-fluid">
<div class="box">.container-fluid (Full Width)</div>
</div>
<!-- Responsive Container: 100% until breakpoint -->
<div class="container-md">
<div class="box">.container-md (100% width until "md", then fixed)</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.7/dist/js/bootstrap.bundle.min.js" integrity="sha384-ndDqU0Gzau9qJ1lfW4pNLlhNTkCfHzAVBReH9diLvGRem5+R9g2FzA8ZGN954O5Q" crossorigin="anonymous"></script>
</body>
</html>
Class | Behavior |
.container | Fixed width depending on screen size (centered layout) |
.container-fluid | Always full-width (100%) across all screen sizes |
.container-md | Full-width below md breakpoint (768px), fixed-width above it |
Components in Bootstrap
๐น Buttons:
<button class="btn btn-primary">Primary</button>
<button class="btn btn-outline-success">Outline</button>
๐น Navbar:
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<div class="container-fluid">
<a class="navbar-brand" href="#">MySite</a>
<button class="navbar-toggler" ... ></button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav">
<li class="nav-item"><a class="nav-link active" href="#">Home</a></li>
</ul>
</div>
</div>
</nav>
๐น Card:
<div class="card" style="width: 18rem;">
<img src="..." class="card-img-top" alt="...">
<div class="card-body">
<h5 class="card-title">Title</h5>
<p class="card-text">Some text.</p>
<a href="#" class="btn btn-primary">Go</a>
</div>
</div>
๐น Form:
<form>
<div class="mb-3">
<label class="form-label">Email</label>
<input type="email" class="form-control" />
</div>
<button class="btn btn-success">Submit</button>
</form>
๐น Alerts:
<div class="alert alert-warning" role="alert">
This is a warning alert!
</div>
0
Subscribe to my newsletter
Read articles from Koustav Moitra directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
