Bootstrap Tutorial menu

Bootstrap Text, Colors and Spacing

Utility classes are small Bootstrap classes that do one job, such as centring text or adding a margin.

Typography

Bootstrap styles headings and text for you. These classes change them further:

ClassEffect
display-1 to display-6Very large, eye-catching headings
leadA slightly larger intro paragraph
fw-bold, fw-semibold, fw-normal, fw-lightFont weight
fst-italicItalic text
fs-1 to fs-6Font size (1 is largest)
text-start, text-center, text-endAlignment
text-uppercase, text-capitalizeLetter case
smallSmaller text

Example

html
<!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>

<div class="container py-4 text-center">
  <p class="text-uppercase fw-semibold small text-secondary">Admissions open</p>
  <h1 class="display-4 fw-bold">Learn IT Skills</h1>
  <p class="lead">Short courses for students and job seekers in Karachi.</p>
  <p class="fst-italic">Classes on weekdays and weekends.</p>
</div>

</body>
</html>
Try it Yourself »

Theme Colours

Bootstrap has a set of named colours. Use them with text- and bg-:

NameTypical use
primaryMain brand colour (blue)
secondaryLess important things (grey)
successDone, correct, paid (green)
dangerErrors, delete (red)
warningWarnings (yellow)
infoInformation (light blue)
light, darkLight grey and near-black

Example

html
<!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-4">

<p class="text-primary">Primary text</p>
<p class="text-success">Your fee is paid.</p>
<p class="text-danger">This roll number is not valid.</p>

<div class="bg-dark text-white p-3 mb-2">Dark background</div>
<div class="bg-warning p-3 mb-2">Warning background</div>
<div class="text-bg-info p-3">text-bg-info picks a readable text colour for you</div>

</body>
</html>
Try it Yourself »

Spacing: Margin and Padding

Spacing classes follow the pattern property, side, size: {m or p}{side}-{size}.

PartOptions
Propertym (margin), p (padding)
Sidet top, b bottom, s start (left), e end (right), x left and right, y top and bottom, blank for all sides
Size0 to 5, or auto

Examples: mt-3 (margin top), px-4 (padding left and right), mb-0 (no bottom margin), mx-auto (centre a block).

SizeSpace
10.25rem
20.5rem
31rem
41.5rem
53rem

Bootstrap uses s (start) and e (end) instead of left and right. This makes layouts work for right-to-left languages like Urdu and Arabic too.

Display and Flex

ClassEffect
d-noneHide the element
d-block, d-inline-blockChange display
d-md-noneHide from the md breakpoint up
d-flexTurn on Flexbox
justify-content-betweenSpace items apart
align-items-centerCentre items vertically
gap-3Space between flex items

Borders, Rounding and Shadows

  • border, border-top, border-primary, border-2 add and colour borders
  • rounded, rounded-3, rounded-pill, rounded-circle round the corners
  • shadow-sm, shadow, shadow-lg add shadows

Example

html
<div class="d-flex justify-content-between align-items-center border rounded-3 shadow-sm p-3">
  <span class="fw-bold">Order #2051</span>
  <span class="badge text-bg-success rounded-pill">Delivered</span>
</div>

Exercise

Exercise

Which class adds padding on the left and right only?

Learn Bootstrap with a teacher

Join the Web Development course at Workownix, online or in Orangi Town, Karachi, and get a certificate.

See the course Ask on WhatsApp