Frontend Development

The Ultimate Comprehensive Guide for Mastering Bootstrap

By the Domain India teamPublished 8 min read
Knowledge base article
Contents (9 sections)

Bootstrap is a free, open-source toolkit of CSS and JavaScript for building responsive websites: a 12-column grid, ready-made components such as navbars, cards, forms and modals, and hundreds of small utility classes. It lets you build a clean, mobile-friendly site without designing every button yourself. This guide covers Bootstrap 5.3, the current major version, from adding it to a page to customising it and avoiding the usual mistakes.

Key takeaways

Add Bootstrap 5.3 with one CSS link and one JavaScript bundle from a CDN, or install it with npm when you want to customise it with Sass. Lay out pages with container, row and col- classes, build interface pieces from components, and fine-tune spacing and colour with utilities. Bootstrap 5 needs no jQuery, and its JavaScript options use data-bs- attributes. Code copied from Bootstrap 4 tutorials often breaks for that reason.

1. What Bootstrap gives you

Grid
A responsive 12-column layout system with six breakpoints, built on flexbox.
Components
Navbars, cards, buttons, forms, alerts, modals, accordions, carousels, toasts and more, with accessible markup.
Utilities
Classes for spacing, colour, display, flex, borders and text, such as mt-3 or text-center.
Colour modes
Light and dark themes switched with one attribute, data-bs-theme.

Bootstrap was created at Twitter and released in 2011. Version 5 dropped jQuery and Internet Explorer support. Version 5.3 added colour modes and many CSS variables. At the time of writing (September 2026), 5.3.8 is the latest release; check getbootstrap.com for newer versions.

2. Add Bootstrap to a page

The quickest start is a CDN. This starter page loads Bootstrap 5.3.8 with integrity hashes, so the browser refuses a file that has been tampered with:

html
<!doctype html>
<html lang="en" data-bs-theme="light">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>My site</title>
  <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
        rel="stylesheet"
        integrity="sha384-sRIl4kxILFvY47J16cr9ZwB07vP4J8+LH7qKQnuqkuIAvNWLzeN8tE5YBujZqJLB"
        crossorigin="anonymous">
</head>
<body>
  <main class="container py-5">
    <h1>Hello, Bootstrap</h1>
  </main>
  <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"
          integrity="sha384-FKyoEForCGlyvwx9Hj09JcYn3nv7wiPVlz7YYwJrWVcXK/BmnVDxM+D2scQbITxI"
          crossorigin="anonymous"></script>
</body>
</html>

The viewport meta tag is essential; without it, phones show a shrunk desktop layout. The bundle file includes Popper, which dropdowns, tooltips and popovers need.

You have three ways to install it:

MethodBest forCustomise with Sass
CDN linksPrototypes, simple sites, learningNo, only by overriding CSS
Download the compiled filesSites that must not depend on a CDNNo, only by overriding CSS
npm with a build tool such as ViteReal projects that need their own themeYes

For an npm project:

bash
npm create vite@latest my-site -- --template vanilla
cd my-site
npm install bootstrap @popperjs/core
npm install --save-dev sass

Then import Bootstrap in your entry file, import './scss/styles.scss' and import * as bootstrap from 'bootstrap', and run npm run build to produce the files you upload.

3. The grid system

Every layout follows the same pattern: a container holds rows, and rows hold columns. A row has 12 units; col-md-6 takes half the width from the medium breakpoint up.

BreakpointClass infixApplies from
Extra smallnone (col-6)0 px
Smallsm576 px
Mediummd768 px
Largelg992 px
Extra largexl1200 px
Extra extra largexxl1400 px

Bootstrap is mobile-first: a class applies at its breakpoint and above. Without a breakpoint class, columns stack on small screens.

html
<div class="container">
  <div class="row g-4">
    <div class="col-12 col-md-6 col-lg-4">Service one</div>
    <div class="col-12 col-md-6 col-lg-4">Service two</div>
    <div class="col-12 col-md-12 col-lg-4">Service three</div>
  </div>
</div>

This shows one column on phones, two on tablets and three on laptops. g-4 sets the gap (gutter) between columns. Use container-fluid for full width, and row-cols-md-3 when every column should be the same width.

4. Components: a responsive navbar and cards

A navbar that collapses into a menu button on small screens:

html
<nav class="navbar navbar-expand-lg bg-body-tertiary">
  <div class="container">
    <a class="navbar-brand" href="index.html">Brand</a>
    <button class="navbar-toggler" type="button" data-bs-toggle="collapse"
            data-bs-target="#mainNav" aria-controls="mainNav"
            aria-expanded="false" aria-label="Toggle navigation">
      <span class="navbar-toggler-icon"></span>
    </button>
    <div class="collapse navbar-collapse" id="mainNav">
      <ul class="navbar-nav ms-auto">
        <li class="nav-item"><a class="nav-link active" aria-current="page" href="index.html">Home</a></li>
        <li class="nav-item"><a class="nav-link" href="services.html">Services</a></li>
        <li class="nav-item"><a class="nav-link" href="contact.html">Contact</a></li>
      </ul>
    </div>
  </div>
</nav>

A card for a product or service:

html
<div class="card h-100 shadow-sm">
  <img src="img/shop.webp" class="card-img-top" alt="Our shop front" loading="lazy">
  <div class="card-body">
    <h2 class="h5 card-title">Home delivery</h2>
    <p class="card-text">Orders placed before 2 pm arrive the same day.</p>
    <a href="delivery.html" class="btn btn-primary">Learn more</a>
  </div>
</div>

Put cards inside grid columns; h-100 makes cards in the same row equal height. Modals, accordions, tabs and toasts follow the same idea: copy the markup from the official documentation and change the content, keeping the aria-* attributes.

5. Forms and validation

Bootstrap 5 styles form controls with form-label, form-control, form-select and form-check. For validation messages, add novalidate and the needs-validation class to the form, a required attribute to fields, and an invalid-feedback element after each field. Then add this script:

javascript
document.querySelectorAll('.needs-validation').forEach((form) => {
  form.addEventListener('submit', (event) => {
    if (!form.checkValidity()) {
      event.preventDefault();
      event.stopPropagation();
    }
    form.classList.add('was-validated');
  });
});

Browser-side validation only helps the visitor. Always validate again on the server, because anyone can bypass the browser.

6. Utilities and colour modes

Utilities let you adjust a component without writing CSS: mt-3 (margin-top), px-4 (horizontal padding), d-none d-md-block (hide on phones), d-flex justify-content-between align-items-center, text-body-secondary, rounded-3, shadow-sm. Spacing runs from 0 to 5, and adding a breakpoint (mb-md-0) makes it responsive.

Set data-bs-theme="dark" on the html element for a dark theme, or on a single element to make only that section dark. Use the bg-body, bg-body-tertiary and text-body classes rather than fixed colours like bg-light, so your page follows the theme.

7. Customise without fighting Bootstrap

In Bootstrap 5.3, most components read CSS variables, so you can restyle them after loading Bootstrap:

css
.btn-primary {
  --bs-btn-bg: #1d4ed8;
  --bs-btn-border-color: #1d4ed8;
  --bs-btn-hover-bg: #1e40af;
  --bs-btn-hover-border-color: #1e40af;
}

For a full theme, use Sass in an npm project. Set variables before importing Bootstrap:

scss
$primary: #1d4ed8;
$border-radius: .5rem;
$font-family-sans-serif: "Inter", system-ui, sans-serif;

@import "bootstrap/scss/bootstrap";

Bootstrap 5.3 still uses Sass @import, so recent Dart Sass versions print deprecation warnings when you build. The build still works.

Bootstrap 4 code breaks in Bootstrap 5

Many tutorials online still show Bootstrap 4 markup. Rename data-toggle and data-target to data-bs-toggle and data-bs-target; ml- and mr- to ms- and me-; custom-select to form-select; and replace form-group with spacing utilities such as mb-3. Bootstrap 5 doesn't need jQuery.

8. Icons, performance and alternatives

Bootstrap Icons is a separate free library of more than 2,000 icons. Add its stylesheet ([email protected] on jsDelivr) and use them as bi bi-telephone classes on an i element, or paste the SVG directly. Give icon-only buttons an aria-label.

The full compiled CSS is about 230 KB before compression. To keep pages fast: import only the Sass parts you use in an npm build, compress images and serve them as WebP, add loading="lazy" to images below the fold, and check that your CSS and JavaScript are served compressed (gzip or Brotli).

If you prefer to write layouts directly in HTML with small utility classes and no ready-made components, look at Tailwind CSS; see the Tailwind CSS handbook. For the fundamentals underneath both, see the CSS guide.

9. Running a Bootstrap site on Domain India

A Bootstrap site is static HTML, CSS and JavaScript, so it runs on any Domain India shared hosting plan. You don't need Node.js on the server. Build on your computer, then upload the output folder to public_html with the File Manager or FTP, using the upload settings guide. Every plan includes free SSL, which also lets you load Bootstrap from a CDN without mixed-content warnings.

If you want a business website without writing HTML at all, the AI Website Builder builds and hosts one for you.

DA Starter
₹100/mo + GST
  • 10 GB NVMe SSD Storage
  • 50 GB Monthly Bandwidth
  • 1 Website
  • 5 Email Accounts
See plan details

The price on the card is a live Domain India list price and excludes 18% GST.

Is Bootstrap free to use for commercial websites?

Yes. Bootstrap is open source under the MIT licence, so you can use it on personal and commercial sites without paying or asking permission. Keep the licence notice that is included in its files.

Does Bootstrap 5 need jQuery?

No. Bootstrap 5 removed jQuery and uses plain JavaScript. Dropdowns, tooltips and popovers need Popper, which is included in the bootstrap.bundle.min.js file.

Why does my Bootstrap navbar toggle button not work?

Usually because the markup comes from Bootstrap 4. In Bootstrap 5 the attributes are data-bs-toggle and data-bs-target. Also check that the bundle JavaScript file is loaded at the end of the body and that the target id matches.

What are the Bootstrap 5 breakpoints?

Small from 576 px, medium from 768 px, large from 992 px, extra large from 1200 px and extra extra large from 1400 px. Below 576 px is extra small, which has no infix. Classes apply at their breakpoint and above.

How do I make a dark theme with Bootstrap?

Since Bootstrap 5.3, add data-bs-theme="dark" to the html element, or to any element to make only that part dark. Use theme-aware classes such as bg-body and text-body instead of fixed colours.

Should I use Bootstrap or Tailwind CSS?

Bootstrap suits you if you want ready-made components and consistent defaults quickly. Tailwind suits you if you want to design every element yourself with utility classes. Both produce fast sites when built properly.

Ready to publish your Bootstrap site? Upload it with the File Manager, or compare plans on DirectAdmin hosting and cPanel hosting.

Put your site online

Shared hosting for static and dynamic sites, with free SSL, weekly backups and a control panel.

See hosting plans

Was this article helpful?

Your answer helps us decide what to improve next.

Still need help? Open a support ticket and our team will reply.

Prefer an app? Add this site to your home screen.Get the app