agyanadda@gmail.com

Bootstrap Flex and Display

Content and Utilities 1 min read Updated Dec 1, 2026 Topic 9 of 32

Display classes

d-none, d-block, d-inline, d-inline-block, d-flex, d-grid

Show or hide by screen size

  • d-none d-md-block — hidden on phones, visible from md up
  • d-md-none — visible on phones only

Flexbox classes

Start with d-flex on the parent, then:

Class Effect
flex-column / flex-row direction
justify-content-between / -center / -end main-axis alignment
align-items-center / -start / -end cross-axis alignment
flex-wrap allow wrapping
flex-grow-1 child takes free space
gap-2 space between children
ms-auto push an item to the right

Centre anything: d-flex justify-content-center align-items-center.

Example

Example — Flex utilities and responsive display HTML
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">

<div class="container my-3">
  <div class="d-flex justify-content-between align-items-center bg-dark text-white p-3 rounded">
    <strong>Logo</strong>
    <div class="d-flex gap-2">
      <a class="btn btn-sm btn-light" href="#">Login</a>
      <a class="btn btn-sm btn-warning" href="#">Sign up</a>
    </div>
  </div>

  <div class="d-flex justify-content-center align-items-center bg-info-subtle mt-3 rounded" style="height: 120px;">Perfectly centred</div>

  <p class="d-none d-md-block alert alert-success mt-3">Visible on md screens and larger</p>
  <p class="d-md-none alert alert-warning mt-3">Visible on small screens only</p>
</div>

Test Yourself With Exercises

Exercise 1 Multiple Choice

Which classes hide an element on phones but show it from md up?

Exercise 2 Fill in the Blank

justify-content-___ puts space between the first and last items.

Exercise 3 True / False

Flex alignment classes work only when the parent has d-flex.

Frequently Asked Questions

Add ms-auto to it (margin-start: auto) inside a d-flex parent.