Category: Bootstrap 5

  • Bootstrap 5 Accordion & Tabs: Copy-Paste Examples (2026)

    Bootstrap 5 Accordion & Tabs: Copy-Paste Examples (2026)

    How the Bootstrap 5 Accordion Works

    The Bootstrap 5 Bootstrap accordion is built on the Collapse plugin. Each panel is controlled by a data-bs-toggle="collapse" attribute pointing to a target element. The accordion wrapper ensures only one panel is open at a time by default.

    Here’s a working three-panel accordion:

    <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" aria-expanded="true" aria-controls="collapseOne">
            What is included in the starter plan?
          </button>
        </h2>
        <div id="collapseOne" class="accordion-collapse collapse show" aria-labelledby="headingOne" data-bs-parent="#faqAccordion">
          <div class="accordion-body">
            The starter plan includes up to 5 projects, basic analytics, and email support.
          </div>
        </div>
      </div>
    
      <div class="accordion-item">
        <h2 class="accordion-header" id="headingTwo">
          <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#collapseTwo" aria-expanded="false" aria-controls="collapseTwo">
            Can I upgrade my plan later?
          </button>
        </h2>
        <div id="collapseTwo" class="accordion-collapse collapse" aria-labelledby="headingTwo" data-bs-parent="#faqAccordion">
          <div class="accordion-body">
            Yes. You can upgrade or downgrade at any time from your account dashboard.
          </div>
        </div>
      </div>
    
      <div class="accordion-item">
        <h2 class="accordion-header" id="headingThree">
          <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#collapseThree" aria-expanded="false" aria-controls="collapseThree">
            Is there a free trial available?
          </button>
        </h2>
        <div id="collapseThree" class="accordion-collapse collapse" aria-labelledby="headingThree" data-bs-parent="#faqAccordion">
          <div class="accordion-body">
            We offer a 14-day free trial with no credit card required.
          </div>
        </div>
      </div>
    
    </div>

    The key mechanics: data-bs-parent="#faqAccordion" links all panels to the wrapper so only one expands at a time. Remove that attribute if you want multiple panels open simultaneously. The collapse show class on the first item marks it as open on load.


    How Bootstrap 5 Tabs Work

    Tabs use the nav-tabs (or nav-pills) component paired with a tab-content container. The connection between tab triggers and panes is made through data-bs-toggle="tab" and matching id / aria-controls values.

    <ul class="nav nav-tabs" id="featureTabs" role="tablist">
      <li class="nav-item" role="presentation">
        <button class="nav-link active" id="design-tab"
          data-bs-toggle="tab"
          data-bs-target="#design"
          type="button" role="tab"
          aria-controls="design"
          aria-selected="true">Design</button>
      </li>
      <li class="nav-item" role="presentation">
        <button class="nav-link" id="development-tab"
          data-bs-toggle="tab"
          data-bs-target="#development"
          type="button" role="tab"
          aria-controls="development"
          aria-selected="false">Development</button>
      </li>
      <li class="nav-item" role="presentation">
        <button class="nav-link" id="deployment-tab"
          data-bs-toggle="tab"
          data-bs-target="#deployment"
          type="button" role="tab"
          aria-controls="deployment"
          aria-selected="false">Deployment</button>
      </li>
    </ul>
    
    
    <div class="tab-content" id="featureTabsContent">
      <div class="tab-pane fade show active" id="design"
        role="tabpanel" aria-labelledby="design-tab">
        <p class="mt-3">Pixel-perfect components built for flexibility across every viewport.</p>
      </div>
      <div class="tab-pane fade" id="development"
        role="tabpanel" aria-labelledby="development-tab">
        <p class="mt-3">Clean, semantic HTML with full Bootstrap 5 utility class support.</p>
      </div>
      <div class="tab-pane fade" id="deployment"
        role="tabpanel" aria-labelledby="deployment-tab">
        <p class="mt-3">One-click deploy to any static host — no build tools required.</p>
      </div>
    </div>

    Swap nav-tabs for nav-pills if you want a rounded button style instead of the underlined tab look. Both work identically under the hood.


    Accordion vs. Tabs: When to Use Each

    They both hide and reveal content, but they serve different UX purposes.

    Use accordions when:

    • Content items are independent of each other (FAQs, feature descriptions, terms)
    • Users may need to compare multiple open panels side by side (disable data-bs-parent)
    • You’re working in a narrow column or sidebar layout
    • Mobile is the primary context — vertical collapse works better on small screens

    Use tabs when:

    • Content represents distinct categories or steps (Pricing tiers, Before/After, Step 1/2/3)
    • Only one view makes sense at a time
    • You want a horizontal layout that mirrors familiar UI patterns (like browser tabs or dashboards)
    • Labeling is short and scannable (one to three words per tab works best)

    A pricing table comparing plans? Tabs. A help center FAQ section? Accordion. A product feature overview with long descriptions? Either works — but accordion handles unequal content lengths more gracefully.

    For a deeper look at how these components fit into full page layouts, the guide on Canvas Template Section Patterns: Building Pages Like a Pro covers practical structure decisions across common page types.


    Customizing Accordion and Tab Styles

    Bootstrap’s defaults are functional but generic. A few CSS overrides go a long way.

    Removing the accordion border and background:

    .accordion-item {
      border: none;
      border-bottom: 1px solid #e5e7eb;
      border-radius: 0 !important;
    }
    
    .accordion-button {
      background-color: transparent;
      font-weight: 600;
      color: #1a1a2e;
      box-shadow: none;
    }
    
    .accordion-button:not(.collapsed) {
      background-color: transparent;
      color: #5c6bc0;
      box-shadow: none;
    }

    Styled pill tabs with custom active state:

    .nav-pills .nav-link {
      border-radius: 50px;
      padding: 0.5rem 1.25rem;
      color: #555;
      font-weight: 500;
      transition: all 0.2s ease;
    }
    
    .nav-pills .nav-link.active {
      background-color: #5c6bc0;
      color: #fff;
    }

    Flush accordion variant (built into Bootstrap — no CSS needed):

    <div class="accordion accordion-flush" id="flushExample">
      
    </div>

    The accordion-flush class removes the outer border and rounded corners, giving you a clean list-style collapse that works well inside cards or sidebars.

    If you’re building out full typography and spacing for these components, Bootstrap 5 Typography: Font Sizes, Weights, and Display Classes is worth a read alongside this — heading weights inside accordion buttons matter more than most people think.


    Accessibility and ARIA Best Practices

    Bootstrap builds accessibility in, but you need to follow the markup conventions correctly for it to hold up.

    For accordions:

    • Always use <button> elements as the toggle — not <a> tags
    • Set aria-expanded="true" on the open panel’s button and "false" on closed ones
    • Link the button to its panel with aria-controls matching the panel’s id
    • Wrap each header in an <h2> (or appropriate heading level for your document outline)

    For tabs:

    • Use role="tablist" on the <ul>, role="tab" on each button, and role="tabpanel" on each pane
    • Set aria-selected="true" on the active tab
    • Link each tab button to its panel via aria-controls and the panel’s aria-labelledby

    Bootstrap’s JavaScript handles keyboard navigation automatically — arrow keys move between tabs, Enter/Space toggles accordions. As long as your markup matches the documented pattern, screen readers and keyboard users get a fully functional experience.

    This matters especially in contexts like healthcare or financial platforms where accessibility compliance isn’t optional. The principles covered in Mental Health Platform Website Design Best Practices go into further depth on building inclusive interactive interfaces.


    Real-World Use Cases and Patterns

    Here’s how these components map to common page sections:

    FAQ page → Accordion with accordion-flush, grouped by topic. Open the most common question by default using collapse show.

    Pricing page → Tabs for plan tiers (Starter / Pro / Enterprise), each pane containing a feature list and CTA button.

    Product features → Nav pills in a horizontal row above a tab content area. Each pane holds a screenshot or short description.

    Onboarding steps → Tabs labeled “Step 1”, “Step 2”, “Step 3” — use JavaScript to programmatically advance tabs as the user completes each step (one line of Bootstrap’s Tab API: bootstrap.Tab.getOrCreateInstance(el).show()).

    Settings panel → Vertical tabs (flex-column nav-pills with col-3 / col-9 grid layout) — Bootstrap supports this with minor layout adjustments.

    <div class="d-flex">
      <div class="nav flex-column nav-pills me-3" id="v-pills-tab" role="tablist">
        <button class="nav-link active" data-bs-toggle="pill"
          data-bs-target="#v-pills-account" type="button" role="tab">Account</button>
        <button class="nav-link" data-bs-toggle="pill"
          data-bs-target="#v-pills-billing" type="button" role="tab">Billing</button>
        <button class="nav-link" data-bs-toggle="pill"
          data-bs-target="#v-pills-notifications" type="button" role="tab">Notifications</button>
      </div>
      <div class="tab-content" id="v-pills-tabContent">
        <div class="tab-pane fade show active" id="v-pills-account" role="tabpanel">Account settings go here.</div>
        <div class="tab-pane fade" id="v-pills-billing" role="tabpanel">Billing details go here.</div>
        <div class="tab-pane fade" id="v-pills-notifications" role="tabpanel">Notification preferences go here.</div>
      </div>
    </div>

    For a broader look at how these components integrate into complete template systems, 8 Bootstrap 5 Card Components You Should Be Using Right Now covers complementary UI building blocks that pair well with tabs and accordions.


    ✅ Key Takeaways

    • Bootstrap 5 accordions use data-bs-toggle="collapse" and data-bs-parent to create mutually exclusive panels — no custom JavaScript needed
    • Bootstrap tabs use data-bs-toggle="tab" with matching id / aria-controls pairs to link triggers and content panes
    • Accordions suit FAQs and vertical layouts; tabs suit parallel categories and horizontal navigation
    • Accessibility is built in — but only if you follow the correct markup structure with proper role and aria-* attributes
    • accordion-flush and nav-pills give you quick style variations without extra CSS
    • Both components are fully customizable with CSS overrides targeting Bootstrap’s modifier classes

    ❓ FAQ

    Q: Do I need to write any JavaScript to use Bootstrap accordions or tabs?
    No. Both components are powered by Bootstrap’s bundled JavaScript plugin. Include bootstrap.bundle.min.js (which includes Popper) in your page and the data-bs-* attributes handle everything. No custom scripts required.

    Q: Can I have multiple accordion panels open at the same time?
    Yes. Remove the data-bs-parent attribute from each .accordion-collapse element. Without it, panels collapse and expand independently — clicking one won’t close the others.

    Q: How do I open a specific tab or accordion panel on page load?
    Add collapse show to the accordion panel’s classes (and set aria-expanded="true" on its button). For tabs, add active to the tab button and show active to the corresponding tab pane.

    Q: Can I link directly to a specific tab using a URL hash?
    Bootstrap doesn’t do this automatically, but it’s achievable with a small snippet that reads window.location.hash on load and triggers the matching tab using bootstrap.Tab.getOrCreateInstance(el).show().

    Q: What’s the difference between nav-tabs and nav-pills?
    Purely visual. nav-tabs gives you the classic underlined tab style. nav-pills gives you filled rounded buttons. Both use the same data-bs-toggle="tab" mechanism and work identically for content switching.


    🚀 Build Faster With Components That Already Work

    Bootstrap 5’s accordion and tab components are powerful — but building an entire project from scratch still takes time. Canvas is a premium HTML template that ships with pre-built accordion and tab sections, dozens of layout patterns, and clean component code ready to drop into any project.

    Explore Canvas and see what’s included →

    If you’re working with the Canvas HTML Template and want to generate production-ready layouts faster, try Canvas Builder free and see how much time you save on every project.

  • Bootstrap 5 Breakpoints: xs, sm, md, lg, xl, xxl (Pixel Values)

    Bootstrap 5 Breakpoints: xs, sm, md, lg, xl, xxl (Pixel Values)

    Responsive design isn’t optional anymore — it’s table stakes. But knowing how Bootstrap 5 handles responsiveness under the hood is what separates a layout that merely looks okay from one that feels intentional on every screen. This guide breaks down Bootstrap 5 breakpoints from first principles, shows you the utility classes that actually matter, and gives you copy-paste snippets you can drop into your next project right now.

    Key Takeaways

    • Bootstrap 5 ships with six named breakpoints: xs, sm, md, lg, xl, and xxl.
    • All breakpoints are mobile-first — styles apply from the given width upward.
    • Grid columns, display utilities, spacing, and typography all accept breakpoint infixes.
    • You can customise breakpoint values in Sass without touching Bootstrap’s source files.
    • Combining breakpoint-aware utilities eliminates the need for most custom media queries.

    What Are Bootstrap 5 Breakpoints?

    A breakpoint is a pixel threshold at which your layout is allowed to reflow. Bootstrap 5 defines six of them, each backed by a Sass variable and an auto-generated set of utility classes:

    Name Infix Min-width Typical target
    Extra small (none) 0px Portrait phones
    Small sm 576px Landscape phones
    Medium md 768px Tablets
    Large lg 992px Laptops
    Extra large xl 1200px Desktops
    Extra extra large xxl 1400px Wide monitors

    The xs tier has no infix — it is the default, unprefixed class. So col-12 means “full-width on all screens”, while col-md-6 means “half-width from 768 px upward, full-width below”.

    This mobile-first philosophy is the most important mental model to internalise. You write the small-screen rule first, then override it as the viewport grows.

    a black and white photo of a pair of shoes
    Photo by Emiliano Vittoriosi on Unsplash

    Grid Columns at Every Breakpoint

    The 12-column grid is Bootstrap’s backbone, and every column class accepts a breakpoint infix. Stack multiple infixes on one element to describe how a column behaves across the full range of devices:

    <div class="container">
      <div class="row g-4">
    
        <!-- Full-width on phones, half on tablets, one-third on desktops -->
        <div class="col-12 col-md-6 col-lg-4">
          <div class="card p-3">Feature A</div>
        </div>
    
        <div class="col-12 col-md-6 col-lg-4">
          <div class="card p-3">Feature B</div>
        </div>
    
        <!-- Sidebar: full-width on phones, full on tablet, one-third on desktop -->
        <div class="col-12 col-lg-4">
          <div class="card p-3">Sidebar</div>
        </div>
    
      </div>
    </div>

    Reading left to right: col-12 covers xs through sm. col-md-6 kicks in at 768 px and overrides the twelve-column rule. col-lg-4 takes over at 992 px. Bootstrap uses a cascade of min-width media queries, so each infix simply overrides the one before it at the appropriate threshold.

    For masonry-style cards and feature grids, 8 Bootstrap 5 Card Components You Should Be Using Right Now pairs well with this technique — it shows how card variants interact with responsive column stacking.

    Display and Visibility Utilities

    Sometimes you don’t want to reflow content — you want to hide it entirely on certain screens. Bootstrap’s responsive display utilities make this clean:

    <!-- Visible only on mobile (xs/sm) -->
    <div class="d-block d-md-none">
      <p>📱 Mobile nav placeholder</p>
    </div>
    
    <!-- Visible only on md and above -->
    <div class="d-none d-md-block">
      <nav class="navbar">Full desktop nav</nav>
    </div>
    
    <!-- Flex layout that becomes a column on small screens -->
    <div class="d-flex flex-column flex-md-row gap-3">
      <div class="p-3 bg-light">Column / Row item 1</div>
      <div class="p-3 bg-light">Column / Row item 2</div>
      <div class="p-3 bg-light">Column / Row item 3</div>
    </div>

    The pattern is always d-{breakpoint}-{value}. Values include none, block, inline, flex, grid, and more. Combining d-none with a breakpoint-specific d-{bp}-block lets you toggle entire sections without a single line of custom CSS.

    The same breakpoint logic governs text alignment, spacing, and type scale. If you’re fine-tuning font sizes across screen sizes, the companion guide Bootstrap 5 Typography: Font Sizes, Weights, and Display Classes covers every responsive typography utility in detail.

    graphical user interface, website
    Photo by PiggyBank on Unsplash

    Responsive Spacing and Sizing

    Padding and margin utilities also accept breakpoint infixes, which is enormously useful for hero sections and call-to-action banners that need generous breathing room on desktop but compact padding on mobile:

    <!-- Hero section: tight on mobile, spacious on desktop -->
    <section class="py-5 py-lg-7 px-3 px-md-5 text-center bg-primary text-white">
      <h1 class="display-4 display-md-2 fw-bold">Build Faster, Launch Smarter</h1>
      <p class="lead mt-3 mb-4">Everything you need, none of what you don't.</p>
      <a href="#" class="btn btn-light btn-lg">Get Started Free</a>
    </section>

    Note the py-5 py-lg-7 pattern: 3 rem of vertical padding on all screens, bumping to a larger custom value at the lg breakpoint. If you’re using the Canvas HTML template, utility spacing up to *-9 is available out of the box — pairing nicely with Bootstrap’s native scale.

    Width and height sizing utilities (w-25, w-50, w-100, etc.) can also be scoped to breakpoints using the same infix pattern, giving you precise control over image and container sizing at every tier.

    Customising Breakpoints with Sass

    The default thresholds won’t fit every project. Bootstrap 5 is built on Sass, so you can override any breakpoint before the framework compiles. The key is to update the $grid-breakpoints and (if you use containers) $container-max-widths maps in your own stylesheet — never in Bootstrap’s source files:

    <!-- In your custom _variables.scss (import BEFORE bootstrap) -->
    
    /*
      Override Bootstrap 5 breakpoints
      Always import this file before @use 'bootstrap'
    */
    
    $grid-breakpoints: (
      xs:   0,
      sm:   480px,   // was 576px — better for modern phones
      md:   768px,
      lg:   1024px,  // was 992px
      xl:   1280px,  // was 1200px
      xxl:  1536px   // was 1400px
    );
    
    $container-max-widths: (
      sm:   460px,
      md:   740px,
      lg:   980px,
      xl:   1240px,
      xxl:  1496px
    );

    After recompiling, every breakpoint-aware utility class in Bootstrap — grids, displays, spacing, flex, order — automatically reflects your new values. You get the full utility API without duplicating a single media query.

    If you’re shipping customised layouts to clients, documenting these overrides is essential. The 11 Things to Check Before Delivering an HTML Template to a Client checklist includes a prompt specifically for flagging Sass customisations so handoffs don’t turn into support tickets.

    Practical Responsive Layout Patterns

    Putting it all together, here are two production-ready patterns that combine breakpoints, grid, flex, and spacing utilities into real-world components:

    Pattern 1 — Responsive pricing row (stacked on mobile, inline on desktop):

    <div class="container py-5">
      <div class="row row-cols-1 row-cols-md-3 g-4 justify-content-center">
    
        <div class="col">
          <div class="card h-100 text-center p-4 border-0 shadow-sm">
            <h3 class="h5 fw-semibold">Starter</h3>
            <p class="display-5 fw-bold my-3">$9</p>
            <a href="#" class="btn btn-outline-primary">Choose Plan</a>
          </div>
        </div>
    
        <div class="col">
          <div class="card h-100 text-center p-4 border-primary shadow">
            <span class="badge bg-primary mb-2">Most Popular</span>
            <h3 class="h5 fw-semibold">Pro</h3>
            <p class="display-5 fw-bold my-3">$29</p>
            <a href="#" class="btn btn-primary">Choose Plan</a>
          </div>
        </div>
    
        <div class="col">
          <div class="card h-100 text-center p-4 border-0 shadow-sm">
            <h3 class="h5 fw-semibold">Enterprise</h3>
            <p class="display-5 fw-bold my-3">$79</p>
            <a href="#" class="btn btn-outline-primary">Choose Plan</a>
          </div>
        </div>
    
      </div>
    </div>

    row-cols-1 stacks all three cards on mobile. row-cols-md-3 switches to a three-column inline layout at the md breakpoint. Zero custom CSS required.

    Pattern 2 — Sidebar layout (content-first on mobile, side-by-side on desktop):

    <div class="container py-5">
      <div class="row g-5">
    
        <!-- Main content: 8/12 cols on lg, full-width below -->
        <main class="col-12 col-lg-8 order-2 order-lg-1">
          <h2>Article Title</h2>
          <p>Your main content goes here...</p>
        </main>
    
        <!-- Sidebar: 4/12 cols on lg, full-width + reordered below -->
        <aside class="col-12 col-lg-4 order-1 order-lg-2">
          <div class="bg-light p-4 rounded">
            <h5>Related Posts</h5>
            <ul class="list-unstyled">
              <li><a href="#">Link one</a></li>
              <li><a href="#">Link two</a></li>
            </ul>
          </div>
        </aside>
    
      </div>
    </div>

    The order-* utilities reorder elements visually without touching the DOM — meaning the main article appears first in source order (better for SEO and screen readers) while the sidebar renders below it on mobile and beside it on desktop.

    Frequently Asked Questions

    What is the default breakpoint in Bootstrap 5?

    The default (unprefixed) tier is xs, which starts at 0 px. Any class without a breakpoint infix — such as col-6 or d-flex — applies from the smallest possible screen size upward. This is the foundation of Bootstrap’s mobile-first approach.

    Can I add a custom breakpoint to Bootstrap 5?

    Yes. Add a new key-value pair to the $grid-breakpoints Sass map before importing Bootstrap, then recompile. Bootstrap will auto-generate all utility classes (grid columns, display, spacing, flex, etc.) for your new breakpoint. Just ensure the map stays in ascending order by pixel value.

    What is the difference between col-md-6 and col-lg-6?

    col-md-6 applies a 6-column (50%) width from 768 px and wider. col-lg-6 does the same but only from 992 px and wider. Below those thresholds, the element falls back to whichever smaller-breakpoint class is also applied — or to full-width (col-12) if none is specified.

    Does Bootstrap 5 still use jQuery for its responsive components?

    No. Bootstrap 5 dropped the jQuery dependency entirely. All interactive components — including the responsive Bootstrap navbar collapse — are powered by vanilla JavaScript bundled with Bootstrap. This reduces page weight and removes a legacy dependency.

    How do I debug which breakpoint is active on my page?

    A simple debugging trick is to add a fixed badge in the corner of your layout that shows the active tier. Add this snippet during development and remove it before going live:

    <div class="position-fixed bottom-0 end-0 p-2 bg-dark text-white small z-3">
      <span class="d-inline d-sm-none">XS</span>
      <span class="d-none d-sm-inline d-md-none">SM</span>
      <span class="d-none d-md-inline d-lg-none">MD</span>
      <span class="d-none d-lg-inline d-xl-none">LG</span>
      <span class="d-none d-xl-inline d-xxl-none">XL</span>
      <span class="d-none d-xxl-inline">XXL</span>
    </div>

    If you’re working with the Canvas HTML Template and want to generate production-ready layouts faster, try Canvas Builder free and see how much time you save on every project.

  • Bootstrap 5 Font Weight Classes: fw-bold, fw-semibold & More

    Bootstrap 5 Font Weight Classes: fw-bold, fw-semibold & More

    Typography is one of the fastest ways to make or break a web layout — and Bootstrap 5 gives you a surprisingly powerful set of tools to get it right without writing much custom CSS. Whether you are setting up a SaaS homepage, a property platform, or a portfolio, understanding how Bootstrap handles font sizes, weights, and display headings will save you hours of tweaking.

    Key Takeaways

    • Bootstrap 5 ships with a complete typographic scale — from utility classes for font size and weight through to oversized display headings — all usable without custom CSS.
    • Display classes (display-1 through display-6) are designed for hero sections and large headings where standard h1–h6 tags are too restrained.
    • Font weight and line-height utilities let you fine-tune readability and hierarchy across any section of a page.
    • The Canvas Builder layout generator pairs directly with Bootstrap 5 typography, so you can prototype type-heavy layouts in minutes.

    Bootstrap 5 Typography Defaults: What You Start With

    Before touching a single class, Bootstrap 5 already sets sensible typographic defaults. The base font size is 16px (1rem), with a line height of 1.5 applied to the <body>. Headings h1 through h6 follow a consistent scale using rem units, which means they scale proportionally with the user’s browser font settings — an important accessibility detail that many developers overlook.

    The default heading scale in Bootstrap 5 is:

    Tag Default Size
    h1 2.5rem (40px)
    h2 2rem (32px)
    h3 1.75rem (28px)
    h4 1.5rem (24px)
    h5 1.25rem (20px)
    h6 1rem (16px)

    Bootstrap also ships with .h1 through .h6 classes, which apply identical styles to any element — useful when you need the visual weight of a heading on a <p> or <span> without breaking document semantics.

    <!-- Semantic heading -->
    <h2>This is a heading</h2>
    
    <!-- Same visual style on a paragraph -->
    <p class="h2">This looks like an h2 but stays a paragraph</p>
    a black and white photo of some type of letters
    Photo by Taso Katsionis on Unsplash

    Display Classes: When Standard Headings Are Not Enough

    For hero sections, landing pages, and any place where you need text to command attention, Bootstrap 5 display classes are the right tool. The six classes — display-1 through display-6 — render text at sizes ranging from roughly 5rem down to 2.5rem, with a lighter font weight (300) and tighter line height than standard headings.

    <h1 class="display-1">Massive Hero Title</h1>
    <h1 class="display-2">Slightly Smaller</h1>
    <h2 class="display-3">Section Hero Heading</h2>
    <h2 class="display-4">Feature Block Title</h2>
    <h3 class="display-5">Card Hero Text</h3>
    <h3 class="display-6">Subtle Large Heading</h3>

    A practical pattern for a hero section using the Canvas HTML Template would combine a display-2 or display-3 class with a lead paragraph and a call-to-action button — giving you a clear visual hierarchy without any custom CSS:

    <section class="py-5 text-center">
      <div class="container">
        <h1 class="display-2 fw-bold">Build Better Layouts</h1>
        <p class="lead text-muted mb-4">
          AI-powered HTML generation for the Canvas template.
        </p>
        <a href="#" class="btn btn-primary btn-lg">Get Started Free</a>
      </div>
    </section>

    This same structure works well for free trial landing pages, where clear typographic hierarchy reduces friction and moves users toward conversion.

    Bootstrap Font Size Utilities: The fs- Classes

    Bootstrap 5 introduced fs- utility classes (fs-1 through fs-6) that mirror the heading size scale but apply only the font size — not the heading weight or margin. This is particularly useful for inline elements, labels, badges, and any case where you want size without heading semantics.

    <p class="fs-1">Largest paragraph text (2.5rem)</p>
    <p class="fs-3">Medium text (1.75rem)</p>
    <span class="fs-5">Small label text (1.25rem)</span>
    <small class="fs-6">Fine print at base size (1rem)</small>

    Where display- classes are for impact, fs- classes are for precision. Use them when you need a specific size in a card subtitle, a stat callout, or a testimonials author line — anywhere the standard paragraph size is either too large or too small.

    white and black box on white table
    Photo by Brands&People on Unsplash

    Font Weight and Style: fw- and fst- Classes

    Typographic hierarchy is not just about size — weight and style do just as much work. Bootstrap 5 ships with a complete set of font weight utilities via the fw- prefix and font style utilities via fst-.

    Available fw- classes:

    • fw-bold — weight 700
    • fw-bolder — bolder than the parent element
    • fw-semibold — weight 600
    • fw-medium — weight 500
    • fw-normal — weight 400 (default body)
    • fw-light — weight 300
    • fw-lighter — lighter than the parent element
    <p class="fw-bold">Bold text — draws the eye immediately</p>
    <p class="fw-semibold">Semibold — softer emphasis</p>
    <p class="fw-light">Light weight — great for display captions</p>
    
    <!-- Combine with display classes for refined hero text -->
    <h1 class="display-3 fw-bold">Convert More Visitors</h1>
    <h2 class="display-5 fw-light text-muted">Simple. Fast. Effective.</h2>

    For font style, fst-italic applies font-style: italic and fst-normal resets it. These are particularly useful for quotes, captions, and testimonial blocks — the kind of components explored in detail in the post on Bootstrap 5 card components.

    Lead Paragraphs and Text Utility Classes

    The .lead class is one of Bootstrap’s most underused typographic tools. It increases paragraph font size to 1.25rem and reduces font weight slightly, making it ideal for introductory text, hero subtitles, and section openers that need to feel authoritative without competing with the heading above.

    <h2 class="display-5 fw-bold">Why Typography Matters</h2>
    <p class="lead">
      Good type choices communicate trust before a user reads a single word.
      Bootstrap 5 gives you the classes to get there without a design team.
    </p>

    Beyond .lead, Bootstrap’s text utilities cover a wide range of typographic adjustments:

    • Alignment: text-start, text-center, text-end (with responsive variants like text-md-start)
    • Transform: text-uppercase, text-lowercase, text-capitalize
    • Decoration: text-decoration-underline, text-decoration-none, text-decoration-line-through
    • Wrapping: text-wrap, text-nowrap, text-truncate
    • Colour: text-primary, text-muted, text-dark, text-white
    <!-- Uppercase label above a heading -->
    <span class="text-uppercase fw-semibold text-muted fs-6 d-block mb-2">
      Case Study
    </span>
    <h3 class="fw-bold">How Proptech Platforms Use Canvas</h3>
    <p class="lead">A real-world example of display hierarchy in practice.</p>

    This uppercase label pattern is used consistently in well-structured multi-section layouts — a technique covered thoroughly in Canvas Template section patterns.

    Combining Classes for Real Bootstrap Design Patterns

    Individual typography utilities become powerful when combined. A stat block, a pricing header, and a testimonial all call for different combinations of size, weight, and colour — but all built from the same Bootstrap classes.

    <!-- Stat block -->
    <div class="text-center py-4">
      <p class="display-4 fw-bold text-primary mb-0">98%</p>
      <p class="fs-5 fw-medium text-dark">Customer Satisfaction</p>
      <p class="fs-6 text-muted">Based on 2025 user survey</p>
    </div>
    
    <!-- Section intro -->
    <div class="mb-5">
      <span class="text-uppercase fw-semibold fs-6 text-muted d-block mb-1">Features</span>
      <h2 class="display-6 fw-bold">Everything you need to ship fast</h2>
      <p class="lead text-muted">Built on Bootstrap 5, designed for Canvas.</p>
    </div>
    
    <!-- Testimonial -->
    <blockquote class="border-start border-primary border-3 ps-4">
      <p class="fs-4 fw-light fst-italic">
        "Canvas Builder cut our build time by more than half."
      </p>
      <footer class="fs-6 fw-semibold text-muted">— Sarah T., Lead Developer</footer>
    </blockquote>

    These patterns require no custom stylesheet entries. Every size, weight, colour, and spacing value comes directly from Bootstrap 5’s utility layer — which is exactly what makes the framework so efficient for rapid prototyping and production builds alike. If you want to explore how these patterns translate into full page builds, the AI Prompt Helper can generate Canvas-compatible section prompts based on your layout goals.

    Frequently Asked Questions

    What is the difference between Bootstrap display classes and heading tags?

    Standard heading tags (h1–h6) apply a size scale with bold weight and document semantics. Display classes (display-1–display-6) apply much larger sizes with a lighter font weight (300), intended purely for visual impact in hero sections and banners — they carry no additional semantic meaning beyond the tag they are applied to.

    Can I use Bootstrap 5 font classes without the full Bootstrap framework?

    The utility classes like fw-bold, fs-3, and text-uppercase are part of Bootstrap’s compiled CSS. You can use Bootstrap’s CDN for just the CSS layer if you do not need the JavaScript components, giving you access to all typography utilities with a single stylesheet link and no build step.

    How do I change the default Bootstrap font to a custom Google Font?

    Bootstrap 5 uses a native font stack by default. To override it, import your chosen Google Font in your <head> and then set body { font-family: 'Your Font', sans-serif; } in your custom CSS file. If you are using Sass, override the $font-family-base variable before importing Bootstrap.

    Are Bootstrap 5 typography classes responsive?

    Font size utilities (fs-) and display classes are not responsive by default — they apply a fixed size at all Bootstrap breakpoint tester. However, you can combine them with Bootstrap’s responsive display utilities or write breakpoint-specific overrides in your custom CSS. Alignment utilities like text-md-center are responsive out of the box.

    What is the .lead class in Bootstrap 5 and when should I use it?

    The .lead class increases paragraph text to 1.25rem with a slightly lighter weight, making it ideal for introductory text directly beneath a heading — in hero sections, feature intros, or the opening paragraph of a content block. It creates visual separation between the heading and the body copy without the full impact of a display class.

    Getting typography right is one of the highest-leverage improvements you can make to any web layout. Bootstrap 5 gives you the full toolkit — from display headings to fine-grained weight and size utilities — and the try Canvas Builder free to see how these classes come together in production-ready Canvas sections without writing a single line of custom CSS.