Display utilities help you quickly show or hide elements on your webpage. They make your page look good on all devices without writing extra CSS.
Display utilities in Bootsrap
class="d-{value} d-{breakpoint}-{value}"
d- controls display like block, inline, none, etc.
{breakpoint} is optional and controls when the display applies (e.g., sm, md, lg, xl, xxl).
<div class="d-none">Hidden on all screens</div>
<div class="d-block d-md-none">Visible only on small screens</div>
<span class="d-inline d-lg-none">Inline on small and medium, hidden on large</span>
<p class="d-flex">Flex container always visible</p>
This page shows four boxes with different display utilities. The first box is hidden everywhere. The second shows only on small screens. The third is inline on small and medium but hidden on large. The last is always visible as a flex container.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>Bootstrap Display Utilities Example</title> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet"> </head> <body> <main class="container mt-4"> <h1>Display Utilities Demo</h1> <div class="d-none bg-primary text-white p-2 mb-2">Hidden on all screens</div> <div class="d-block d-md-none bg-success text-white p-2 mb-2">Visible only on small screens (block)</div> <div class="d-inline d-lg-none bg-warning text-dark p-2 mb-2">Inline on small/medium, hidden on large</div> <div class="d-flex bg-info text-white p-2 mb-2">Flex container always visible</div> </main> </body> </html>
Use d-none to hide elements completely.
Combine display utilities with breakpoints like d-md-block to control visibility on different screen sizes.
Remember that hidden elements with d-none are removed from the layout and not focusable.
Display utilities let you quickly show or hide elements without writing CSS.
You can control display on different screen sizes using breakpoint classes.
They help make your site responsive and user-friendly on all devices.
Practice
d-none do to an element?Solution
Step 1: Understand the
Thed-noneclass purposed-noneclass in Bootstrap sets the CSS propertydisplay: none;which hides the element completely.Step 2: Confirm effect on all screen sizes
Since no breakpoint is specified,d-noneapplies to all screen sizes, hiding the element everywhere.Final Answer:
It hides the element on all screen sizes. -> Option AQuick Check:
d-none= hide element always [OK]
- Thinking d-none only hides on small screens
- Confusing d-none with color or interaction changes
- Assuming it disables the element
Solution
Step 1: Understand breakpoint classes for visibility
d-nonehides the element on all screens, andd-md-blockshows it as block starting from medium screens and up.Step 2: Combine classes to show only on medium and larger
Usingd-none d-md-blockhides the element on small and extra small screens, then shows it on medium and larger.Final Answer:
d-none d-md-block -> Option AQuick Check:
Hide all + show md+ = d-none d-md-block [OK]
- Using d-md-none which hides on medium screens
- Confusing d-block and d-none order
- Using wrong breakpoints like d-sm-block d-md-none
<div class="d-none d-lg-block">Hello</div>
Solution
Step 1: Analyze the classes
d-noneandd-lg-blockd-nonehides the element on all screen sizes by default.d-lg-blockoverrides this to show the element as block starting at large screens (lg) and above.Step 2: Determine visibility on screen sizes
From extra small to medium screens, the element is hidden. From large screens and up, it becomes visible as a block element.Final Answer:
Visible only on large screens and above -> Option CQuick Check:
d-none + d-lg-block = show lg+ only [OK]
- Thinking it is visible on all screens
- Confusing d-lg-block as hiding on large screens
- Ignoring the effect of d-none
Solution
Step 1: Understand the goal and class effects
To hide only on small screens, the element should be visible by default and hidden on small screens only.Step 2: Analyze each option's effect
d-none d-sm-blockhides the element on all screens by default, then shows it from small screens and up. This means it is hidden only on extra small screens, not small screens.Final Answer:
d-none d-sm-block -> Option DQuick Check:
Hide all then show sm+ hides xs only, not sm [OK]
- Mixing up small (sm) and extra small (xs) breakpoints
- Using d-none without proper show class
- Assuming d-sm-block hides on small screens
Solution
Step 1: Break down the requirements by screen size
Extra small (xs) and small (sm): hidden
Medium (md) and large (lg): visible as block
Extra large (xl): visible as inlineStep 2: Match classes to requirements
d-nonehides on all by default (xs and sm included).d-md-blockshows block from medium and up (md, lg, xl).d-xl-inlineoverrides to inline only on extra large screens.Step 3: Verify other options
Other options either hide wrong breakpoints or use incorrect display types at breakpoints.Final Answer:
d-none d-md-block d-xl-inline -> Option BQuick Check:
Hide all, show block md+, inline xl = d-none d-md-block d-xl-inline [OK]
- Using d-sm-none hides only small, not extra small
- Mixing inline and block classes at wrong breakpoints
- Forgetting to hide on extra small screens
Ready to prove it?
Pass the test and this pattern moves unknown
