← Learning Hub
Beginner

Flex, Display and Next Steps

Bootstrap has classes for flexbox and for showing or hiding things on different screen sizes.

These are the same flexbox ideas from the CSS course, as ready-made classes. d-flex with alignment classes handles most small layouts: a header with a logo on the left and buttons on the right, an icon next to text, or items centred in a box. Display classes let you hide things on small screens (like a long description) and show them on bigger ones.

Example
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
  </head>
  <body class="p-3">
    <div class="d-flex justify-content-between align-items-center border rounded p-2 mb-3">
      <b>Cart total: Rs 1,860</b>
      <button class="btn btn-success btn-sm">Checkout</button>
    </div>

    <div class="d-flex flex-wrap gap-2">
      <span class="badge text-bg-secondary">Phones</span>
      <span class="badge text-bg-secondary">Laptops</span>
      <span class="badge text-bg-secondary">Watches</span>
    </div>

    <p class="d-none d-md-block mt-3 text-primary">You see this only on medium and bigger screens.</p>
    <p class="d-md-none mt-3 text-danger">You see this only on small screens.</p>
  </body>
</html>
▶ Try it yourself
  • d-flex turns on flexbox; justify-content-between spreads items out; align-items-center lines them up in the middle.
  • d-none hides; d-md-block shows again from medium screens.
  • gap-2 adds space between flex items.

What to learn next

  • Bootstrap Icons, a free icon set that matches Bootstrap.
  • Change colours and fonts with Sass variables or CSS variables.
  • Build a full page: navbar, product cards, a form and a footer.
Key points
  • d-flex, justify-content-*, align-items-* for flexbox.
  • d-none / d-md-block show or hide by screen size.
  • Next: Bootstrap Icons and custom themes.

📝 Test yourself

1. Which class turns on flexbox?
2. What does d-none d-md-block do?
3. Fill in the class that adds space between flex items:
<div class="d-flex -3">