Azwar's Blog
Bootstrap 5 Development: Building Responsive Websites with Modern CSS Framework
Hi everyone! I'm Azwar, a WordPress and frontend developer. In this comprehensive guide, I'll walk you through Bootstrap 5 development, from basic setup to advanced customization. Bootstrap is one of the most popular CSS frameworks, and mastering it will help you create responsive, modern websites efficiently.

Bootstrap 5 is the latest version of the popular CSS framework that makes responsive web development faster and easier. With its powerful grid system, pre-built components, and extensive utility classes, Bootstrap helps developers create professional-looking websites quickly.
Getting Started with Bootstrap 5
Installation Options
Option 1: CDN (Quick Start)
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Bootstrap 5 Website</title> <!-- Bootstrap CSS --> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet"> <!-- Bootstrap Icons --> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.0/font/bootstrap-icons.css"> </head> <body> <!-- Your content here --> <!-- Bootstrap JS --> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script> </body> </html>
Option 2: NPM Installation
npm install bootstrap@5.3.0
Option 3: Custom Build with Sass
npm install bootstrap@5.3.0 sass
Understanding the Grid System
Bootstrap's grid system is based on a 12-column layout that adapts to different screen sizes:
<div class="container"> <div class="row"> <!-- Equal columns --> <div class="col-md-6"> <div class="card"> <div class="card-body"> <h5 class="card-title">Column 1</h5> <p class="card-text">This column takes up 6 columns on medium screens and larger.</p> </div> </div> </div> <div class="col-md-6"> <div class="card"> <div class="card-body"> <h5 class="card-title">Column 2</h5> <p class="card-text">This column also takes up 6 columns on medium screens and larger.</p> </div> </div> </div> </div> <!-- Responsive columns --> <div class="row mt-4"> <div class="col-12 col-sm-6 col-md-4 col-lg-3"> <div class="card"> <div class="card-body"> <h6 class="card-title">Responsive Column</h6> <p class="card-text">This column adapts to different screen sizes.</p> </div> </div> </div> <div class="col-12 col-sm-6 col-md-4 col-lg-3"> <div class="card"> <div class="card-body"> <h6 class="card-title">Responsive Column</h6> <p class="card-text">This column adapts to different screen sizes.</p> </div> </div> </div> <div class="col-12 col-sm-6 col-md-4 col-lg-3"> <div class="card"> <div class="card-body"> <h6 class="card-title">Responsive Column</h6> <p class="card-text">This column adapts to different screen sizes.</p> </div> </div> </div> <div class="col-12 col-sm-6 col-md-4 col-lg-3"> <div class="card"> <div class="card-body"> <h6 class="card-title">Responsive Column</h6> <p class="card-text">This column adapts to different screen sizes.</p> </div> </div> </div> </div> </div>
Building a Modern Navigation Bar
Create responsive navigation with Bootstrap 5:
<nav class="navbar navbar-expand-lg navbar-dark bg-primary"> <div class="container"> <a class="navbar-brand" href="#"> <i class="bi bi-code-slash"></i> My Website </a> <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav"> <span class="navbar-toggler-icon"></span> </button> <div class="collapse navbar-collapse" id="navbarNav"> <ul class="navbar-nav me-auto"> <li class="nav-item"> <a class="nav-link active" href="#home">Home</a> </li> <li class="nav-item"> <a class="nav-link" href="#about">About</a> </li> <li class="nav-item"> <a class="nav-link" href="#services">Services</a> </li> <li class="nav-item"> <a class="nav-link" href="#contact">Contact</a> </li> </ul> <form class="d-flex"> <input class="form-control me-2" type="search" placeholder="Search"> <button class="btn btn-outline-light" type="submit">Search</button> </form> </div> </div> </nav>
Creating Hero Sections
Build attractive hero sections with Bootstrap components:
<section class="hero-section bg-primary text-white py-5"> <div class="container"> <div class="row align-items-center"> <div class="col-lg-6"> <h1 class="display-4 fw-bold mb-4"> Build Amazing Websites with Bootstrap 5 </h1> <p class="lead mb-4"> Create responsive, modern websites quickly with Bootstrap's powerful components and utilities. </p> <div class="d-flex gap-3"> <button class="btn btn-light btn-lg"> Get Started </button> <button class="btn btn-outline-light btn-lg"> Learn More </button> </div> </div> <div class="col-lg-6"> <img src="hero-image.jpg" alt="Hero Image" class="img-fluid rounded"> </div> </div> </div> </section>
Building Feature Cards
Create attractive feature cards with Bootstrap:
<section class="features-section py-5"> <div class="container"> <div class="row text-center mb-5"> <div class="col-lg-8 mx-auto"> <h2 class="display-5 fw-bold">Our Features</h2> <p class="lead text-muted"> Discover what makes our platform special </p> </div> </div> <div class="row g-4"> <div class="col-md-6 col-lg-4"> <div class="card h-100 border-0 shadow-sm"> <div class="card-body text-center p-4"> <div class="feature-icon bg-primary bg-gradient text-white rounded-circle d-inline-flex align-items-center justify-content-center mb-3" style="width: 60px; height: 60px;"> <i class="bi bi-lightning-charge fs-3"></i> </div> <h5 class="card-title">Fast Performance</h5> <p class="card-text text-muted"> Optimized for speed and efficiency, ensuring your website loads quickly. </p> </div> </div> </div> <div class="col-md-6 col-lg-4"> <div class="card h-100 border-0 shadow-sm"> <div class="card-body text-center p-4"> <div class="feature-icon bg-success bg-gradient text-white rounded-circle d-inline-flex align-items-center justify-content-center mb-3" style="width: 60px; height: 60px;"> <i class="bi bi-phone fs-3"></i> </div> <h5 class="card-title">Mobile First</h5> <p class="card-text text-muted"> Responsive design that looks great on all devices and screen sizes. </p> </div> </div> </div> <div class="col-md-6 col-lg-4"> <div class="card h-100 border-0 shadow-sm"> <div class="card-body text-center p-4"> <div class="feature-icon bg-info bg-gradient text-white rounded-circle d-inline-flex align-items-center justify-content-center mb-3" style="width: 60px; height: 60px;"> <i class="bi bi-shield-check fs-3"></i> </div> <h5 class="card-title">Secure & Reliable</h5> <p class="card-text text-muted"> Built with security in mind, keeping your data safe and protected. </p> </div> </div> </div> </div> </div> </section>
Creating Forms with Bootstrap
Build beautiful, responsive forms:
<section class="contact-section py-5 bg-light"> <div class="container"> <div class="row justify-content-center"> <div class="col-lg-8"> <div class="card border-0 shadow"> <div class="card-body p-5"> <h3 class="text-center mb-4">Contact Us</h3> <form> <div class="row"> <div class="col-md-6 mb-3"> <label for="firstName" class="form-label">First Name</label> <input type="text" class="form-control" id="firstName" required> </div> <div class="col-md-6 mb-3"> <label for="lastName" class="form-label">Last Name</label> <input type="text" class="form-control" id="lastName" required> </div> </div> <div class="mb-3"> <label for="email" class="form-label">Email Address</label> <input type="email" class="form-control" id="email" required> <div class="form-text">We'll never share your email with anyone else.</div> </div> <div class="mb-3"> <label for="subject" class="form-label">Subject</label> <select class="form-select" id="subject" required> <option value="">Choose a subject</option> <option value="general">General Inquiry</option> <option value="support">Technical Support</option> <option value="billing">Billing Question</option> </select> </div> <div class="mb-3"> <label for="message" class="form-label">Message</label> <textarea class="form-control" id="message" rows="5" required></textarea> </div> <div class="mb-3 form-check"> <input type="checkbox" class="form-check-input" id="newsletter"> <label class="form-check-label" for="newsletter"> Subscribe to our newsletter </label> </div> <div class="d-grid"> <button type="submit" class="btn btn-primary btn-lg"> Send Message </button> </div> </form> </div> </div> </div> </div> </div> </section>
Building a Pricing Table
Create attractive pricing tables:
<section class="pricing-section py-5"> <div class="container"> <div class="row text-center mb-5"> <div class="col-lg-8 mx-auto"> <h2 class="display-5 fw-bold">Choose Your Plan</h2> <p class="lead text-muted"> Select the perfect plan for your needs </p> </div> </div> <div class="row g-4 justify-content-center"> <div class="col-lg-4 col-md-6"> <div class="card h-100 border-0 shadow-sm"> <div class="card-body p-4"> <div class="text-center mb-4"> <h5 class="card-title">Starter</h5> <div class="pricing-price"> <span class="display-4 fw-bold">$9</span> <span class="text-muted">/month</span> </div> </div> <ul class="list-unstyled"> <li class="mb-2"> <i class="bi bi-check text-success me-2"></i> Up to 5 projects </li> <li class="mb-2"> <i class="bi bi-check text-success me-2"></i> Basic support </li> <li class="mb-2"> <i class="bi bi-check text-success me-2"></i> 10GB storage </li> <li class="mb-2 text-muted"> <i class="bi bi-x text-muted me-2"></i> Advanced features </li> </ul> <div class="d-grid"> <button class="btn btn-outline-primary">Get Started</button> </div> </div> </div> </div> <div class="col-lg-4 col-md-6"> <div class="card h-100 border-primary border-2 shadow"> <div class="card-body p-4"> <div class="text-center mb-4"> <span class="badge bg-primary mb-2">Most Popular</span> <h5 class="card-title">Professional</h5> <div class="pricing-price"> <span class="display-4 fw-bold">$29</span> <span class="text-muted">/month</span> </div> </div> <ul class="list-unstyled"> <li class="mb-2"> <i class="bi bi-check text-success me-2"></i> Up to 20 projects </li> <li class="mb-2"> <i class="bi bi-check text-success me-2"></i> Priority support </li> <li class="mb-2"> <i class="bi bi-check text-success me-2"></i> 100GB storage </li> <li class="mb-2"> <i class="bi bi-check text-success me-2"></i> Advanced features </li> </ul> <div class="d-grid"> <button class="btn btn-primary">Get Started</button> </div> </div> </div> </div> <div class="col-lg-4 col-md-6"> <div class="card h-100 border-0 shadow-sm"> <div class="card-body p-4"> <div class="text-center mb-4"> <h5 class="card-title">Enterprise</h5> <div class="pricing-price"> <span class="display-4 fw-bold">$99</span> <span class="text-muted">/month</span> </div> </div> <ul class="list-unstyled"> <li class="mb-2"> <i class="bi bi-check text-success me-2"></i> Unlimited projects </li> <li class="mb-2"> <i class="bi bi-check text-success me-2"></i> 24/7 support </li> <li class="mb-2"> <i class="bi bi-check text-success me-2"></i> 1TB storage </li> <li class="mb-2"> <i class="bi bi-check text-success me-2"></i> All features included </li> </ul> <div class="d-grid"> <button class="btn btn-outline-primary">Get Started</button> </div> </div> </div> </div> </div> </div> </section>
Custom Theming with Sass
Create custom Bootstrap themes using Sass:
// Custom variables $primary: #007bff; $secondary: #6c757d; $success: #28a745; $info: #17a2b8; $warning: #ffc107; $danger: #dc3545; $light: #f8f9fa; $dark: #343a40; // Custom font $font-family-sans-serif: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif; // Custom spacing $spacer: 1rem; $spacers: ( 0: 0, 1: $spacer * .25, 2: $spacer * .5, 3: $spacer, 4: $spacer * 1.5, 5: $spacer * 3, 6: $spacer * 4, 7: $spacer * 5, ); // Custom border radius $border-radius: .375rem; $border-radius-sm: .25rem; $border-radius-lg: .5rem; // Import Bootstrap @import "bootstrap/scss/bootstrap"; // Custom styles .hero-section { background: linear-gradient(135deg, $primary 0%, darken($primary, 15%) 100%); } .feature-icon { transition: transform 0.3s ease; &:hover { transform: scale(1.1); } } .card { transition: transform 0.3s ease, box-shadow 0.3s ease; &:hover { transform: translateY(-5px); box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1) !important; } } .btn { border-radius: $border-radius; font-weight: 500; transition: all 0.3s ease; &:hover { transform: translateY(-2px); } }
Responsive Utilities
Use Bootstrap's responsive utilities effectively:
<!-- Responsive text alignment --> <p class="text-start text-md-center text-lg-end"> This text aligns differently on different screen sizes. </p> <!-- Responsive display --> <div class="d-none d-md-block"> This content is hidden on mobile but visible on medium screens and up. </div> <div class="d-block d-md-none"> This content is visible on mobile but hidden on medium screens and up. </div> <!-- Responsive spacing --> <div class="p-3 p-md-4 p-lg-5"> This element has different padding on different screen sizes. </div> <!-- Responsive grid --> <div class="row"> <div class="col-12 col-sm-6 col-md-4 col-lg-3 col-xl-2"> <div class="card"> <div class="card-body"> <h6>Responsive Card</h6> <p class="small">This card adapts to screen size.</p> </div> </div> </div> </div>
Best Practices for Bootstrap Development
- Mobile First: Always design for mobile first, then enhance for larger screens
- Use Semantic HTML: Combine Bootstrap classes with semantic HTML elements
- Customize Responsibly: Use Sass variables for customization instead of overriding CSS
- Optimize Performance: Only include the Bootstrap components you need
- Accessibility: Ensure your Bootstrap components are accessible
- Consistent Spacing: Use Bootstrap's spacing utilities consistently
- Test Responsively: Test your website on various devices and screen sizes
Conclusion
Bootstrap 5 is a powerful framework that makes responsive web development faster and more efficient. By mastering its grid system, components, and utilities, you can create professional-looking websites that work perfectly on all devices.
Remember to always prioritize user experience, follow Bootstrap best practices, and create websites that are both beautiful and functional.