Bootstrap 5 – Utility API
Estimated reading: 4 minutes 11 views

🖥️ Bootstrap 5 – Display Utilities: Show, Hide, and Toggle Elements Easily


🧲 Introduction – What Are Bootstrap 5 Display Utilities?

Bootstrap 5 includes powerful display utility classes that allow developers to control the visibility and display type of HTML elements without writing custom CSS. Whether you want to hide/show content across breakpoints or change how elements behave (block, inline, flex), these utilities offer a responsive, mobile-first way to manage layouts.

🎯 In this guide, you’ll learn:

  • How to use .d-* classes to manage display types
  • Responsive visibility toggling across breakpoints
  • Best use cases for hiding/showing elements on specific devices
  • Real-world UI use cases like nav menus, cards, and form sections

✅ Example 1 – Display Block and Inline Elements

<p class="d-block">I’m displayed as a block element</p>
<span class="d-inline">I’m inline</span>
ClassDescription
.d-blockForces element to display as block
.d-inlineDisplays element as inline

🔍 Result: The paragraph takes full width, while the span appears inline with adjacent content.


✅ Example 2 – Hide and Show Elements

<div class="d-none">This is hidden</div>
<div class="d-block">This is visible</div>
ClassBehavior
.d-noneHides the element (display: none)
.d-blockMakes the element visible again

✅ Useful for conditional rendering, collapsible content, and modals.


✅ Example 3 – Responsive Show/Hide (Mobile to Desktop)

<div class="d-none d-md-block">Visible only on md and up</div>
<div class="d-block d-md-none">Visible only on mobile</div>
ClassEffect
.d-noneHides by default on all devices
.d-md-blockShows as block on medium (≥768px) and up
.d-md-noneHides from medium and above

🧪 Perfect for: Navigation menus, filters, footers, or banners that should be device-specific.


✅ Example 4 – Toggle Between Display Modes

<div class="d-inline d-sm-block d-lg-inline-block">
  I'm inline by default, block on small, inline-block on large+
</div>
ClassBehavior
.d-inlineDefault on extra-small (XS)
.d-sm-blockBlock on small (≥576px)
.d-lg-inline-blockInline-block on large (≥992px)

💡 Responsive UI Tip: This technique is great for building adaptive toolbars or responsive text alignment blocks.


📊 Display Utility Classes Reference Table

ClassDescription
.d-nonedisplay: none
.d-inlinedisplay: inline
.d-inline-blockdisplay: inline-block
.d-blockdisplay: block
.d-griddisplay: grid
.d-tabledisplay: table
.d-table-celldisplay: table-cell
.d-flexdisplay: flex
.d-inline-flexdisplay: inline-flex

📱 Each of these classes can be extended responsively:

  • .d-sm-none, .d-md-flex, .d-lg-inline, etc.

🛠️ Best Practices for Display Utilities

TipWhy It Matters
Use .d-none + breakpoint classesTo hide/show content responsively across screen sizes
Avoid using .d-* for layout hacksUse grid/flex utilities instead for structured layouts
Combine with .visually-hidden for a11yUse .visually-hidden for screen readers, not .d-none
Test on real devicesHidden elements may still occupy space depending on context

📌 Summary – Mastering Display Utilities in Bootstrap 5

Bootstrap 5 display utilities make responsive visibility and layout toggling seamless. You can show, hide, or alter the display type of elements at different breakpoints without custom CSS.

🔍 Key Takeaways:

  • .d-none hides elements completely
  • Use .d-* classes to switch between block, flex, inline, etc.
  • Combine breakpoints like .d-md-none, .d-lg-flex for device-based control
  • Don’t confuse .d-none with .visually-hidden (they serve different purposes)

⚙️ Great for responsive navs, alerts, sidebars, headers, and mobile-optimized interfaces.


❓ FAQs – Bootstrap 5 Display Utilities

What is the difference between .d-none and .visually-hidden?
.d-none removes the element visually and from screen readers. .visually-hidden hides it visually but still keeps it accessible to assistive tech like screen readers.


How do I hide an element only on small devices?
✅ Use .d-none d-sm-block. This hides the element on XS and shows from SM (576px+) onwards.


Can I apply multiple .d-* classes for different breakpoints?
✅ Yes! Example: .d-none d-md-block d-lg-flex toggles the element’s display type at each screen size.


Can I switch between grid and flex using display utilities?
✅ Absolutely. Use .d-grid, .d-flex, or .d-inline-flex as needed. Combine with responsive utilities for even more control.


Share Now :

Leave a Reply

Your email address will not be published. Required fields are marked *

Share

Bootstrap 5 – Display Utilities

Or Copy Link

CONTENTS
Scroll to Top