Discover how a few simple classes can save you hours of CSS headaches!
Why Visibility utilities in Bootsrap? - Purpose & Use Cases
Imagine you want to show or hide parts of your webpage depending on the screen size, like hiding a sidebar on a phone but showing it on a desktop.
If you try to do this manually, you have to write lots of custom CSS rules and media queries. It's easy to make mistakes, and testing every screen size takes a lot of time.
Bootstrap's visibility utilities let you quickly show or hide elements with simple classes. You don't write custom CSS or media queries; just add the right class and it works across devices.
.sidebar { display: none; } @media (min-width: 768px) { .sidebar { display: block; } }<div class="d-none d-md-block sidebar">Sidebar content</div>
You can easily control what users see on different devices, making your site look great everywhere without extra CSS hassle.
On a news website, you might hide large images on phones to save data and show them on desktops for a richer experience, all by toggling visibility classes.
Manual CSS for visibility is slow and error-prone.
Bootstrap visibility utilities simplify responsive showing/hiding.
They save time and improve user experience across devices.
Practice
d-none do to an element?Solution
Step 1: Understand the
Thed-noneclass purposed-noneclass setsdisplay: none;on the element, hiding it completely.Step 2: Effect on layout
Because the element is removed from the layout flow, it takes no space on the page.Final Answer:
It hides the element completely, removing it from the layout. -> Option CQuick Check:
d-nonehides element fully [OK]
d-none means no display at all [OK]- Confusing
d-nonewithinvisible - Thinking it only hides visually but keeps space
- Assuming it only works on small screens
Solution
Step 1: Understand breakpoint classes
d-nonehides the element on all screen sizes.d-md-blockmakes it display block starting at medium screens and up.Step 2: Combine classes for desired visibility
Usingd-none d-md-blockhides the element on small and extra small screens, shows it on medium and larger.Final Answer:
<code>d-none d-md-block</code> -> Option BQuick Check:
Hide all, show from medium up =d-none d-md-block[OK]
d-none plus breakpoint d-*-block to show [OK]- Reversing the breakpoint classes order
- Using
d-block d-md-nonewhich hides on medium screens - Confusing
smandmdbreakpoints
<div class="invisible">Hello</div>
What will you see in the browser?
Solution
Step 1: Understand the
Theinvisibleclass effectinvisibleclass appliesvisibility: hidden;, hiding the content but keeping its space.Step 2: Visual result in browser
The text won't be seen, but the element's space remains reserved on the page.Final Answer:
The text 'Hello' is hidden but the space remains. -> Option AQuick Check:
invisiblehides content but keeps layout space [OK]
invisible hides text but keeps space [OK]- Thinking
invisibleremoves element from layout - Confusing
invisiblewithd-none - Expecting text to show on some screen sizes
Solution
Step 1: Analyze
d-none d-sm-blockd-nonehides element on all sizes,d-sm-blockshows it from small screens up, so it remains hidden on extra small but visible on small and larger.Step 2: Check requirement
The requirement is to hide on small screens but show on medium and larger. This combination shows on small screens, so it is incorrect.Final Answer:
<code>d-none d-sm-block</code> -> Option AQuick Check:
Hide on small, show medium up needsd-none d-md-block[OK]
- Using
d-sm-blockinstead ofd-md-block - Adding redundant classes that conflict
- Assuming
d-nonecan be overridden by smaller breakpoint
Solution
Step 1: Understand the requirement
Hide the paragraph on xs and sm screens, make it visible on md and larger.Step 2: Analyze correct option
d-none d-md-blocksetsdisplay: noneby default (hides completely on xs/sm), thendisplay: blockfrom md up (visible on md+).Step 3: Why other options fail
A and C use non-existentd-md-visible. D usesinvisiblewhich appliesvisibility: hiddeneverywhere, so remains hidden even on md+.Final Answer:
<code>d-none d-md-block</code> -> Option DQuick Check:
Hide xs/sm completely, show md+ =d-none d-md-block[OK]
d-none d-md-block to hide below medium, show from medium [OK]- Using
invisiblewhich keeps space but stays hidden on large screens - Using non-existent classes like
d-md-visible - Not understanding breakpoint overrides for display
Ready to prove it?
Pass the test and this pattern moves unknown
