← Learning Hub
Beginner

Text, Colours and Spacing

Utility classes each do one small job. Mixing them saves you from writing CSS.

Utility classes are tiny, single-purpose classes: one adds a margin, one makes text bold, one colours the background. Instead of writing a new CSS rule for every small tweak, you combine utilities right in the HTML. It's fast, and anyone reading the HTML can see exactly how an element is styled.

Colours

Theme colours: primary, secondary, success, danger, warning, info, light, dark. Use them with text- and bg-.

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">
    <p class="text-success fw-bold">In stock</p>
    <p class="text-danger">Only 2 left!</p>
    <p class="bg-dark text-white p-2 rounded">Dark box with white text</p>
    <p class="text-center text-uppercase small">Free delivery above Rs 499</p>
  </body>
</html>
▶ Try it yourself

Spacing: margin and padding

The pattern is property + side + size: m = margin, p = padding; sides t top, b bottom, s start, e end, x left and right, y top and bottom; sizes 0 to 5.

Spacing is what makes a design feel clean. Bootstrap uses a fixed scale (0 to 5) so spacing stays consistent across the whole site. For example mb-3 means margin-bottom size 3, and px-4 means padding left and right size 4. Once you learn the pattern, you can read and write them without looking up anything.

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="bg-info-subtle p-4 mb-3">p-4: big padding, mb-3: margin below</div>
    <div class="bg-info-subtle px-5 py-1">px-5 py-1: wide sides, thin top and bottom</div>
    <div class="bg-warning-subtle mt-4 ms-5 p-2">mt-4 ms-5: pushed down and to the right</div>
  </body>
</html>
▶ Try it yourself
fw-bold makes text bold, fs-4 changes the size, and rounded rounds corners.
Key points
  • Utilities are small classes that each do one job.
  • Colours: text-* and bg-* with theme names.
  • Spacing: property (m/p) + side (t/b/s/e/x/y) + size (0-5).

📝 Test yourself

1. What does the class mb-3 add?
2. Which class makes text red for an error?
3. Fill in the class that centres text:
<p class="text-">