Layout Lesson 5 of 12
Bootstrap Utilities — Spacing, Colors, Text and Flex
Style anything quickly with Bootstrap utilities — margin and padding (m-3, px-4), text and background colors, typography, borders, shadows, sizing and flex helpers.
Utility classes are tiny, single-purpose classes like mt-3 (margin-top) or text-center. Combining them lets you style elements without writing CSS. They're the part of Bootstrap you'll use most.
Spacing: margin and padding
The pattern is property + side + size:
| Part | Options |
|---|---|
| Property | m = margin, p = padding |
| Side | t top, b bottom, s start (left), e end (right), x left+right, y top+bottom, nothing = all sides |
| Size | 0 to 5 (0, 4px, 8px, 16px, 24px, 48px), or auto |
<link rel="stylesheet" href="/vendor/bootstrap.min.css">
<div class="container">
<div class="bg-light border mt-3 p-1">mt-3 p-1</div>
<div class="bg-light border mt-2 p-3">mt-2 p-3</div>
<div class="bg-light border mt-2 px-5 py-2">px-5 py-2</div>
<div class="bg-warning-subtle border mt-2 mx-auto p-2" style="width: 200px">mx-auto (centered)</div>
</div>
Responsive versions exist too: p-2 p-md-5 means small padding on phones, large padding from medium screens up.
Colors
Bootstrap has named theme colors: primary, secondary, success, danger, warning, info, light and dark.
<link rel="stylesheet" href="/vendor/bootstrap.min.css">
<div class="container py-3">
<p class="text-primary">text-primary</p>
<p class="text-success">text-success: PASSED</p>
<p class="text-danger">text-danger: FAILED</p>
<p class="text-body-secondary">text-body-secondary (muted)</p>
<div class="bg-success text-white p-2 mb-1">bg-success text-white</div>
<div class="bg-warning-subtle p-2 mb-1">bg-warning-subtle</div>
<div class="text-bg-dark p-2">text-bg-dark (sets both)</div>
</div>
Text and typography
<link rel="stylesheet" href="/vendor/bootstrap.min.css">
<div class="container py-3">
<h1 class="display-6">display-6 heading</h1>
<p class="lead">lead: a bigger intro paragraph.</p>
<p class="fw-bold">fw-bold</p>
<p class="fst-italic">fst-italic</p>
<p class="text-uppercase small">text-uppercase small</p>
<p class="text-center">text-center</p>
<p class="text-end">text-end</p>
<p class="text-decoration-line-through">text-decoration-line-through</p>
</div>
Borders, rounded corners and shadows
<link rel="stylesheet" href="/vendor/bootstrap.min.css">
<div class="container py-3 d-flex gap-3">
<div class="p-3 border">border</div>
<div class="p-3 border border-primary border-2 rounded">border-primary rounded</div>
<div class="p-3 rounded-3 shadow-sm">shadow-sm</div>
<div class="p-3 rounded-pill shadow">shadow rounded-pill</div>
</div>
Flex utilities
<link rel="stylesheet" href="/vendor/bootstrap.min.css">
<div class="container py-3">
<div class="d-flex justify-content-between align-items-center p-2 border mb-2">
<strong>Aral Code</strong>
<div class="d-flex gap-2">
<a href="#" class="btn btn-sm btn-outline-primary">Login</a>
<a href="#" class="btn btn-sm btn-primary">Sign up</a>
</div>
</div>
<div class="d-flex flex-column flex-md-row gap-2">
<div class="p-2 bg-light border flex-fill">One</div>
<div class="p-2 bg-light border flex-fill">Two</div>
<div class="p-2 bg-light border flex-fill">Three</div>
</div>
</div>
d-flex makes a flex container. justify-content-between, align-items-center, gap-2, flex-column and flex-md-row all match the Flexbox properties from the CSS course.
Sizing
w-25, w-50, w-75, w-100 set width as a percentage; h-100 sets full height; mw-100 keeps images from overflowing. img-fluid makes an image shrink to fit its container.
Quick Quiz
Check what you learned. Walang grade ito, practice lang. 🙂
By Sir Reyel · Last updated 2026-12-04