← Learning Hub
Intermediate

Images, Borders, Shadows and Helpers

Bootstrap's utility classes each do one small job. You can style a lot without writing any CSS.

Utilities cover the small finishing touches that make a page look polished - responsive images, rounded corners, subtle shadows, consistent borders - without opening a CSS file. Because they're standard class names, any Bootstrap developer can read your HTML and immediately understand how each element is styled.

  • Images: img-fluid (never wider than its parent), rounded, rounded-circle, img-thumbnail
  • Borders: border, border-0, border-primary, rounded-3, rounded-pill
  • Shadows: shadow-sm, shadow, shadow-lg
  • Sizes: w-25, w-50, w-100, h-100, mw-100
  • Position: position-relative, position-absolute top-0 end-0, sticky-top
  • Text: text-truncate, text-nowrap, small, lh-sm
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 gap-3 align-items-center flex-wrap">
      <img src="https://picsum.photos/120" class="rounded-circle shadow" width="80" height="80" alt="Profile">
      <img src="https://picsum.photos/200/140" class="img-thumbnail" alt="Thumbnail">
      <div class="position-relative border rounded-3 shadow-sm p-3" style="width: 200px">
        <span class="position-absolute top-0 start-100 translate-middle badge rounded-pill text-bg-danger">-40%</span>
        <div class="text-truncate fw-semibold">Super long product name that will not fit</div>
        <div class="small text-body-secondary">Free delivery</div>
      </div>
    </div>
  </body>
</html>
▶ Try it yourself

Ratio: keep the shape

.ratio .ratio-16x9 keeps videos and maps in the right shape on every screen.

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="ratio ratio-16x9" style="max-width: 480px">
      <iframe src="https://www.youtube.com/embed/VIDEO_ID" title="Demo video" allowfullscreen></iframe>
    </div>
  </body>
</html>
▶ Try it yourself

Visibility

  • visually-hidden - hidden on screen but read by screen readers
  • d-none d-md-block - hidden on phones, shown from tablets up
  • opacity-50, invisible - faded or invisible but still taking space
Key points
  • img-fluid makes images responsive.
  • Borders, rounded, shadow and ratio classes style without CSS.
  • visually-hidden keeps text for screen readers only.

📝 Test yourself

1. Which class makes an image shrink to fit small screens?
2. Which class hides text on screen but keeps it for screen readers?
3. Fill in the class that makes a square image round:
<img class="rounded-" src="me.jpg">