Bootstrap Getting Started
Learn how to add Bootstrap to a web project and start building responsive user interfaces step by step.
In the previous topic, we learned what Bootstrap is and why developers use it. Now, at CIIT Training Institute, we will learn how to actually start using Bootstrap in a web project.
What You Will Learn
- How Bootstrap works in a web project
- How to include Bootstrap CSS
- How to include Bootstrap JavaScript
- How to create your first Bootstrap page
- How Bootstrap classes are applied
- How responsive design works
What Do We Need to Use Bootstrap?
To start learning Bootstrap, we need a basic HTML page and Bootstrap CSS and JavaScript files.
| Requirement | Purpose |
|---|---|
| HTML | Creates the structure of the web page. |
| Bootstrap CSS | Provides Bootstrap styling and layout classes. |
| Bootstrap JavaScript | Enables interactive Bootstrap components. |
| Browser | Displays and runs the web page. |
How Bootstrap Works
The basic working flow can be understood with the following diagram.
HTML
Page Structure
Bootstrap CSS
Styling & Layout
Browser
Final UI
Step 1: Create an HTML Page
First, create a basic HTML document. This document will contain the structure of our web page.
<!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>
</head>
<body>
<h1>Welcome to Bootstrap</h1>
</body>
</html>
Step 2: Add Bootstrap CSS
Bootstrap CSS provides predefined classes that we can use directly in our HTML elements.
For example, instead of writing custom CSS for a button, we can use Bootstrap's button classes.
<link
href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css"
rel="stylesheet">
Think of Bootstrap CSS as a ready-made design toolkit. Instead of creating every style yourself, you can use Bootstrap's predefined classes.
Step 3: Add Bootstrap JavaScript
Some Bootstrap components require JavaScript for their interactive behavior, such as dropdowns, modals, carousels and other components.
<script
src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js">
</script>
Step 4: Use Bootstrap Classes
Once Bootstrap CSS is available, we can apply Bootstrap classes directly to HTML elements.
<button class="btn btn-primary">
Login
</button>
Understanding the Code
| Class | Meaning |
|---|---|
btn
|
Applies basic Bootstrap button styling. |
btn-primary
|
Applies the primary button style. |
Output
Complete Bootstrap Example
Now let's combine HTML structure, Bootstrap CSS and Bootstrap classes into one simple page.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, initial-scale=1.0">
<title>Bootstrap Example</title>
<link
href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css"
rel="stylesheet">
</head>
<body>
<div class="container mt-5">
<h1 class="text-primary">
Welcome to CIIT Training Institute
</h1>
<p class="lead">
Learn Bootstrap step by step.
</p>
<button class="btn btn-primary">
Start Learning
</button>
</div>
</body>
</html>
Simple Real-Life Example
Think of Bootstrap Like a Ready-Made Toolkit
Imagine a carpenter has to build a table. Instead of making every tool from scratch, the carpenter uses ready-made tools. Bootstrap works in a similar way for web developers. It gives us ready-made classes and components so we can build a professional UI faster.
Bootstrap and Responsive Design
One of the biggest advantages of Bootstrap is responsive design. The same website can adapt to different screen sizes.
Desktop
Large screen layout
Tablet
Medium screen layout
Mobile
Small screen layout
Common Mistakes
- Forgetting to include Bootstrap CSS.
- Using Bootstrap classes incorrectly.
- Forgetting Bootstrap JavaScript for interactive components.
- Not using the responsive grid correctly.
Summary
In this lesson, we learned how to get started with Bootstrap. We created a basic HTML page, added Bootstrap CSS, understood Bootstrap JavaScript and learned how to apply Bootstrap classes.
We also understood how Bootstrap helps developers create responsive web pages and saw a simple CIIT Training Institute example.