📖 Scenario: You are building a simple webpage that shows different messages depending on the screen size. This helps users see the right content on phones, tablets, and desktops.
🎯 Goal: Create a webpage using Bootstrap visibility utilities to show or hide text blocks on different screen sizes.
📋 What You'll Learn
Use Bootstrap 5 visibility utility classes
Show a message only on small screens
Show a message only on medium screens
Show a message only on large screens
Use semantic HTML and include accessibility attributes
💡 Why This Matters
🌍 Real World
Websites often need to show or hide content depending on the device size to improve user experience and readability.
💼 Career
Understanding Bootstrap visibility utilities is useful for front-end developers to create responsive and accessible web pages quickly.
Progress0 / 4 steps
1
Create the HTML skeleton with Bootstrap link
Write the basic HTML5 structure with lang="en", meta charset="UTF-8", and viewport meta tag. Include the Bootstrap 5 CSS link from CDN inside the <head>. Add a <main> section with an empty <div> container with class container and id messages.
Bootsrap
Hint
Remember to include the Bootstrap CSS link inside the <head> section.
2
Add messages for small, medium, and large screens
Inside the <div id="messages" class="container">, add three <p> elements with these exact texts: "Visible only on small screens", "Visible only on medium screens", and "Visible only on large screens". Do not add any classes yet.
Bootsrap
Hint
Make sure the texts match exactly and are inside separate <p> tags.
3
Add Bootstrap visibility utility classes to paragraphs
Add the Bootstrap classes to each <p> to control visibility: add d-block d-sm-none to the small screen message, d-none d-sm-block d-md-none to the medium screen message, and d-none d-md-block d-lg-none to the large screen message.
Bootsrap
Hint
Use the Bootstrap display utility classes exactly as shown to control visibility by screen size.
4
Add accessibility and finalize the page
Add aria-live="polite" to the <div id="messages"> container to announce changes to screen readers. Also add a <header> with a <h1> titled "Responsive Visibility Example" above the <main>. Ensure the page is complete and valid.
Bootsrap
Hint
Adding aria-live="polite" helps screen readers announce changes politely. The header gives a clear page title.
Practice
(1/5)
1. What does the Bootstrap class d-none do to an element?
easy
A. It changes the element to display as a block.
B. It makes the element invisible but keeps its space.
C. It hides the element completely, removing it from the layout.
D. It makes the element visible only on small screens.
Solution
Step 1: Understand the d-none class purpose
The d-none class sets display: 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 C
Quick Check:
d-none hides element fully [OK]
Hint: Remember: d-none means no display at all [OK]
Common Mistakes:
Confusing d-none with invisible
Thinking it only hides visually but keeps space
Assuming it only works on small screens
2. Which of the following is the correct way to make an element visible only on medium and larger screens using Bootstrap classes?
easy
A. d-md-none d-lg-block
B. d-none d-md-block
C. d-block d-md-none
D. d-none d-sm-block
Solution
Step 1: Understand breakpoint classes
d-none hides the element on all screen sizes. d-md-block makes it display block starting at medium screens and up.
Step 2: Combine classes for desired visibility
Using d-none d-md-block hides the element on small and extra small screens, shows it on medium and larger.
Final Answer:
<code>d-none d-md-block</code> -> Option B
Quick Check:
Hide all, show from medium up = d-none d-md-block [OK]
Hint: Use d-none plus breakpoint d-*-block to show [OK]
Common Mistakes:
Reversing the breakpoint classes order
Using d-block d-md-none which hides on medium screens
Confusing sm and md breakpoints
3. Given this HTML snippet:
<div class="invisible">Hello</div>
What will you see in the browser?
medium
A. The text 'Hello' is hidden but the space remains.
B. The text 'Hello' is visible and takes space.
C. The text 'Hello' is hidden and no space is taken.
D. The text 'Hello' is visible only on large screens.
Solution
Step 1: Understand the invisible class effect
The invisible class applies visibility: 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 A
Quick Check:
invisible hides content but keeps layout space [OK]
Hint: invisible hides text but keeps space [OK]
Common Mistakes:
Thinking invisible removes element from layout
Confusing invisible with d-none
Expecting text to show on some screen sizes
4. You want to hide a button on small screens but show it on medium and larger screens. Which Bootstrap class combination is incorrect?
medium
A. d-none d-sm-block
B. d-sm-none d-md-block
C. d-block d-sm-none d-md-block
D. d-none d-md-block
Solution
Step 1: Analyze d-none d-sm-block
d-none hides element on all sizes, d-sm-block shows 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 A
Quick Check:
Hide on small, show medium up needs d-none d-md-block [OK]
Hint: Check breakpoint start points carefully for show/hide [OK]
Common Mistakes:
Using d-sm-block instead of d-md-block
Adding redundant classes that conflict
Assuming d-none can be overridden by smaller breakpoint
5. You want a paragraph to be hidden on extra small and small screens but visible on medium and large screens. Which class combination achieves this?
hard
A. invisible d-md-visible
B. invisible d-md-block
C. invisible d-md-visible d-md-block
D. d-none d-md-block
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-block sets display: none by default (hides completely on xs/sm), then display: block from md up (visible on md+).
Step 3: Why other options fail
A and C use non-existent d-md-visible. D uses invisible which applies visibility: hidden everywhere, so remains hidden even on md+.
Final Answer:
<code>d-none d-md-block</code> -> Option D
Quick Check:
Hide xs/sm completely, show md+ = d-none d-md-block [OK]
Hint: Use d-none d-md-block to hide below medium, show from medium [OK]
Common Mistakes:
Using invisible which keeps space but stays hidden on large screens
Using non-existent classes like d-md-visible
Not understanding breakpoint overrides for display
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.