← Back to Bootstrap Course | Chapter 10: Responsive Design | Lesson 4 of 7

Show/hide by breakpoint

Combine display utilities to show or hide content depending on screen size.

In this page:

  1. Show/hide by breakpoint
Syntax
markup
<div class="d-none d-md-block">hidden below md</div>
<div class="d-lg-none">hidden from lg up</div>

Show/hide by breakpoint

Hide on small screens with d-none d-md-block, hide on large ones with d-lg-none, or show only on a range with combinations such as d-none d-md-block d-xl-none.

Hiding removes content from layout but not from the page, so avoid hiding essential content on mobile.

Note: Prefer restructuring content over hiding it on small screens.

Example: Show/hide by breakpoint

markup
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body class="p-3">
<div class="container text-center">
  <div class="d-block d-sm-none bg-danger text-white p-2 mb-1">xs only</div>
  <div class="d-none d-sm-block d-md-none bg-warning p-2 mb-1">sm only</div>
  <div class="d-none d-md-block d-lg-none bg-success text-white p-2 mb-1">md only</div>
  <div class="d-none d-lg-block bg-primary text-white p-2">lg and up</div>
</div>
</body>
</html>
Live Example
Related Topics
Common Mistakes
  1. Hiding essential content on mobile
  2. Forgetting the counterpart class
  3. Using JavaScript for simple show/hide
Chapter Summary
  • d-none plus d-{bp}-block shows from a size
  • d-{bp}-none hides from a size
  • Combine for ranges
  • Do not hide essential content
🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.