Skip to content

Components of Bootstrap

πŸ”· What are Bootstrap Components?

Bootstrap components are pre-designed, reusable UI elements that help developers build attractive and responsive web interfaces quickly without writing custom CSS or JavaScript.

πŸ“Œ These components are built using HTML, CSS, and Bootstrap’s JavaScript plugins.


βœ… Why Use Bootstrap Components?

  • πŸš€ Faster UI development
  • 🧩 Consistent design across pages
  • 🎨 Built-in styling and responsiveness
  • πŸ’‘ Enhances user experience (UX)

🧱 Categories of Bootstrap Components

Bootstrap components can be grouped under:

CategoryExamples
Layout & ContainersContainer, Grid, Columns
NavigationNavbar, Navs, Breadcrumbs
Forms & InputsForm Controls, Input Groups
Content PresentationCards, Tables, Alerts
Media & OverlaysModals, Carousels, Popovers
Interactive FeaturesButtons, Dropdowns, Collapse
Utility Add-onsBadges, Spinners, Tooltips

πŸ“š Detailed Overview of Bootstrap Components

1️⃣ Buttons (.btn)

<button class="btn btn-primary">Primary Button</button>
<button class="btn btn-success">Success Button</button>
  • Supports different types: primary, secondary, danger, info, warning
  • Can be used for forms, actions, navigation

2️⃣ Cards (.card)

Used to group related content – text, images, buttons.

<div class="card" style="width: 18rem;">
<img src="img.jpg" class="card-img-top" alt="...">
<div class="card-body">
<h5 class="card-title">MCA Course</h5>
<p class="card-text">This is a Bootstrap card example.</p>
<a href="#" class="btn btn-primary">Go somewhere</a>
</div>
</div>

3️⃣ Alerts (.alert)

Used to show messages to the user.

<div class="alert alert-success">Operation completed successfully!</div>
<div class="alert alert-danger">Something went wrong!</div>

4️⃣ Navbar (.navbar)

Responsive header navigation bar.

<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<a class="navbar-brand" href="#">MyApp</a>
<div class="collapse navbar-collapse">
<ul class="navbar-nav">
<li class="nav-item active"><a class="nav-link" href="#">Home</a></li>
<li class="nav-item"><a class="nav-link" href="#">About</a></li>
</ul>
</div>
</nav>

5️⃣ Forms (.form-control, .form-group)

Form elements are styled automatically with Bootstrap classes.

<form>
<div class="mb-3">
<label for="email" class="form-label">Email address</label>
<input type="email" class="form-control" id="email">
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>

6️⃣ Modals (.modal)

Popup windows used for dialogs, alerts, or forms.

<!-- Button -->
<button type="button" class="btn btn-info" data-bs-toggle="modal" data-bs-target="#myModal">Open Modal</button>

<!-- Modal Structure -->
<div class="modal fade" id="myModal">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header"><h5 class="modal-title">Modal Title</h5></div>
<div class="modal-body">This is a Bootstrap modal popup.</div>
<div class="modal-footer"><button class="btn btn-secondary" data-bs-dismiss="modal">Close</button></div>
</div>
</div>
</div>

7️⃣ Carousel (.carousel)

Image slideshow component.

<div id="carouselExample" class="carousel slide" data-bs-ride="carousel">
<div class="carousel-inner">
<div class="carousel-item active"><img src="img1.jpg" class="d-block w-100" alt="..."></div>
<div class="carousel-item"><img src="img2.jpg" class="d-block w-100" alt="..."></div>
</div>
</div>

8️⃣ Badges (.badge)

Used to display small count indicators or labels.

<h4>Messages <span class="badge bg-danger">5</span></h4>

9️⃣ Collapse (.collapse)

Used to toggle visibility of content.

<a class="btn btn-primary" data-bs-toggle="collapse" href="#collapseExample">Toggle Info</a>
<div class="collapse" id="collapseExample">
<div class="card card-body">This content is collapsible.</div>
</div>

πŸ”Ÿ Tooltips & Popovers

These are small hover boxes used for tips and extra information.

<!-- Tooltip -->
<button type="button" class="btn btn-secondary" data-bs-toggle="tooltip" title="Tooltip example">Hover Me</button>

<!-- Popover -->
<button type="button" class="btn btn-warning" data-bs-toggle="popover" title="Popover Title" data-bs-content="This is a popover">Click Me</button>

πŸ”§ These require initialization via JavaScript:

var tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]'));
tooltipTriggerList.map(function (tooltipTriggerEl) {
return new bootstrap.Tooltip(tooltipTriggerEl);
});

πŸ“‹ Summary Table of Bootstrap Components

ComponentPurposeClass Example
ButtonsAction triggersbtn btn-primary
NavbarNavigation menunavbar navbar-light
CardsContent containerscard, card-body
AlertsNotification messagesalert alert-success
FormsUser inputform-control
ModalsPop-up dialog boxesmodal
CarouselImage slideshowcarousel
CollapseExpand/collapse contentcollapse
BadgesDisplay counts/labelsbadge bg-danger
TooltipsShow text on hovertooltip

🧠 Tips

  • Start by practicing with a basic webpage and add components step-by-step.
  • Use Bootstrap documentation: https://getbootstrap.com
  • Use CDN for easy prototyping.
  • Combine multiple components to create real UI: Login forms, product cards, dashboards.

πŸ§‘β€πŸ’» Suggested Mini Projects

  1. Student Profile Card using Bootstrap Card + Badges
  2. Responsive Registration Form using Bootstrap Forms
  3. MCA Course Website Homepage using Navbar, Carousel, and Cards
  4. Popup Feedback Form using Modals
  5. Project Gallery using Grid + Cards + Buttons

🧩 Bootstrap Components – In-depth


πŸ”° Bootstrap Component Architecture

Every component in Bootstrap is built using:

  • HTML structure
  • CSS utility classes
  • (Optional) JavaScript behavior

Let’s explore more Bootstrap components with detailed syntax, features, and examples.


πŸ”Ά 1. Accordion

The Accordion allows toggling content within collapsible items (great for FAQs).

πŸ”Ή Example:

<div class="accordion" id="faqAccordion">
<div class="accordion-item">
<h2 class="accordion-header" id="headingOne">
<button class="accordion-button" type="button" data-bs-toggle="collapse" data-bs-target="#collapseOne">
What is Bootstrap?
</button>
</h2>
<div id="collapseOne" class="accordion-collapse collapse show" data-bs-parent="#faqAccordion">
<div class="accordion-body">
Bootstrap is a front-end toolkit for designing responsive sites.
</div>
</div>
</div>
</div>

βœ… Use Case: Display course modules or FAQs in a collapsible format.


πŸ”Ά 2. List Group

Used for displaying lists of content in a clean and styled manner.

πŸ”Ή Example:

<ul class="list-group">
<li class="list-group-item active">Dashboard</li>
<li class="list-group-item">Profile</li>
<li class="list-group-item">Settings</li>
</ul>

βœ… Use Case: Navigation sidebar in admin panels or user profiles.


πŸ”Ά 3. Pagination

Used to navigate between pages of content (like a blog or data table).

πŸ”Ή Example:

<nav>
<ul class="pagination">
<li class="page-item"><a class="page-link" href="#">Previous</a></li>
<li class="page-item"><a class="page-link" href="#">1</a></li>
<li class="page-item active"><a class="page-link" href="#">2</a></li>
<li class="page-item"><a class="page-link" href="#">Next</a></li>
</ul>
</nav>

βœ… Use Case: Paginate search results, blog posts, or product listings.


πŸ”Ά 4. Progress Bar

Shows task progress like file upload or course completion.

πŸ”Ή Example:

<div class="progress">
<div class="progress-bar" role="progressbar" style="width: 70%;">70%</div>
</div>

βœ… Use Case: Show student progress on a learning management system.


πŸ”Ά 5. Dropdowns

Toggleable menus for options or navigation.

πŸ”Ή Example:

<div class="dropdown">
<button class="btn btn-secondary dropdown-toggle" type="button" data-bs-toggle="dropdown">
Select Course
</button>
<ul class="dropdown-menu">
<li><a class="dropdown-item" href="#">MCA</a></li>
<li><a class="dropdown-item" href="#">MBA</a></li>
</ul>
</div>

βœ… Use Case: Filter options, account menus, selection categories.


πŸ”Ά 6. Spinners (Loaders)

Indicate loading or processing state.

πŸ”Ή Example:

<div class="spinner-border text-primary" role="status">
<span class="visually-hidden">Loading...</span>
</div>

βœ… Use Case: Show while data is loading or forms are being submitted.


πŸ”Ά 7. Breadcrumbs

Shows navigation path (useful for sub-pages or hierarchy).

πŸ”Ή Example:

<nav>
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="#">Home</a></li>
<li class="breadcrumb-item"><a href="#">Courses</a></li>
<li class="breadcrumb-item active">Web Development</li>
</ol>
</nav>

βœ… Use Case: Show current page location within app or site hierarchy.


πŸ”Ά 8. Toast Notifications

Lightweight alert boxes that appear briefly and disappear.

πŸ”Ή Example:

<div class="toast show" role="alert" aria-live="assertive" aria-atomic="true">
<div class="toast-header">
<strong class="me-auto">Notice</strong>
<small>Just now</small>
<button type="button" class="btn-close" data-bs-dismiss="toast"></button>
</div>
<div class="toast-body">
Course added successfully!
</div>
</div>

βœ… Use Case: Notifications like “Login successful”, “File uploaded”, etc.


πŸ”Ά 9. Tooltips & Popovers (Expanded View)

Tooltips show small text on hover; popovers display more info on click.

Tooltip:

<button class="btn btn-info" data-bs-toggle="tooltip" title="This is a tooltip">Hover Me</button>

Popover:

<button class="btn btn-warning" data-bs-toggle="popover" title="More Info" data-bs-content="Details about this topic.">Click Me</button>

βœ… Use Case: Add explanations, hints, or extra info.


🧠 Best Practices When Using Components

  • βœ… Combine components to create complex layouts.
  • βœ… Use container, row, and col for consistent layout.
  • βœ… Use utility classes (mt-3, text-center, etc.) to modify components quickly.
  • βœ… Customize components using SCSS if needed.

πŸ§ͺ Practical Assignments

  1. πŸ”§ Create an Admin Dashboard using cards, navbar, sidebar, progress bar.
  2. πŸ“‹ Design a University Course Page using accordion, list groups, and badges.
  3. πŸ“ Develop a Student Portal with navbars, tabs, forms, and alerts.
  4. πŸ›οΈ Build a Product Gallery using carousel, modal, and grid layout.
  5. πŸ“± Create a Mobile-First Landing Page using responsive utility classes.

πŸŽ“ Summary: Why Learn Bootstrap Components?

BenefitExplanation
πŸ”¨ Pre-built ElementsSave time and effort during development
🎨 Consistent StylingUniform look across the project
πŸ“± Responsive DesignWorks perfectly on mobile, tablet, desktop
🧠 Easy Learning CurveLearn once, apply everywhere