Bootstrap - Text/Typography

With Bootstrap 5, which offers an extensive collection of classes for managing text and typography, you can create elegantly styled text content that fits on any screen size and device. Whether you need to adjust the font size, text color, or text alignment, Bootstrap provides easy-to-use utility classes for efficient typographic management.

We'll look at the many text and typography classes in Bootstrap 5 in this blog post, covering alignment, text colors, headings, paragraphs, and more.

1. Headings

With Bootstrap 5, you can use HTML's <h1> through <h6> tags, which apply variable sizes, to build stylized headings with varying degrees of prominence.

Example:

<h1>This is an H1 heading</h1>

<h2>This is an H2 heading</h2>

<h3>This is an H3 heading</h3>

<h2>This is an H4 heading</h2>

<h5>This is an H5 heading</h5>

<h6>This is an H6 heading</h6>

Each heading tag corresponds to a different font size. The hierarchy goes from <h1>, which is the largest, down to <h6>, which is the smallest.

Custom Heading Sizes:

You can also customize heading sizes with utility classes like .display-1, .display-2, .display-3, and so on, for larger headings.

<h1 class="display-1">Display 1</h1>

<h1 class="display-2">Display 2</h1>

<h1 class="display-3">Display 3</h1>

These display classes are typically used to showcase larger, bolder headings in hero sections.

2. Paragraphs

Bootstrap uses the standard <p> tag for paragraphs, which are styled with default spacing and line height.

Example:

<p>This is a regular paragraph in Bootstrap 5.</p>

You can also adjust the lead paragraph size using the .lead class, which increases the font size slightly.

<p class="lead">This is a lead paragraph for emphasizing important content.</p>

3. Text Alignment

Bootstrap offers several utility classes to align text content within its container:

Left alignment: .text-start

Center alignment: .text-center

Right alignment: .text-end

Example:

<p class="text-start">Left-aligned text.</p>

<p class="text-center">Center-aligned text.</p>

<p class="text-end">Right-aligned text.</p>

For responsive text alignment, you can use breakpoint-specific classes such as .text-sm-start, .text-md-center, and .text-lg-end to adjust text alignment based on the screen size.

Example:

<p class="text-sm-start text-md-center text-lg-end">

    Responsive aligned text.

</p>

4. Font Weights

To control the thickness or thinness of text, Bootstrap provides font-weight utility classes:

Bold text: .fw-bold

Normal text: .fw-normal

Light text: .fw-light

Example:

<p class="fw-bold">Bold text</p>

<p class="fw-normal">Normal text</p>

<p class="fw-light">Light text</p>

Additionally, Bootstrap offers classes like .fw-bolder and .fw-lighter for relative font weights.

5. Text Colors

You can modify text colors easily with Bootstrap's text color utility classes:

Primary text: .text-primary

Secondary text: .text-secondary

Success text: .text-success

Danger text: .text-danger

Warning text: .text-warning

Info text: .text-info

Light text: .text-light

Dark text: .text-dark

Muted text: .text-muted

White text: .text-white

Example:

<p class="text-primary">Primary color text</p>

<p class="text-success">Success color text</p>

<p class="text-danger">Danger color text</p>

<p class="text-muted">Muted color text</p>

These color classes align with Bootstrap’s theme colors, providing a consistent look and feel.

6. Text Transformation

You can control the capitalization of text using text transformation utility classes:

Uppercase: .text-uppercase

Lowercase: .text-lowercase

Capitalize: .text-capitalize

Example:

<p class="text-uppercase">This text is in uppercase.</p>

<p class="text-lowercase">THIS TEXT IS IN LOWERCASE.</p>

<p class="text-capitalize">this text is capitalized.</p>

7. Text Wrapping and Overflow

Bootstrap provides utility classes to control text wrapping and handling overflow text:

No wrap: .text-nowrap prevents text from wrapping to the next line.

Text truncation: .text-truncate shortens the text and appends an ellipsis (...) when it overflows.

Word break: .text-break forces long words to break and wrap onto the next line.

Example:

<p class="text-nowrap">This text will not wrap.</p>

<p class="text-truncate" style="width: 150px;">This long text will be truncated when it exceeds the container width.</p>

<p class="text-break">Thisisaverylongwordthatwillbreakintoanewlinewhenitgetstoolong.</p>

8. Line Height

Bootstrap provides utilities to adjust line height. Use classes like .lh-1, .lh-sm, .lh-base, .lh-lg, and .lh-2 to modify line spacing.

Example:

<p class="lh-1">Line height 1.0</p>

<p class="lh-base">Base line height</p>

<p class="lh-lg">Larger line height</p>

9. Blockquotes

Blockquotes are useful for displaying citations or emphasized content. You can style blockquotes with the .blockquote class.

Example:

<blockquote class="blockquote">

  <p>A famous quote from someone important.</p>

</blockquote>

For citation, add the .blockquote-footer class:

<blockquote class="blockquote">

  <p>A famous quote from someone important.</p>

  <footer class="blockquote-footer">Famous Person <cite title="Source Title">Source Title</cite></footer>

</blockquote>

10. Lists

Bootstrap allows you to customize lists with several utility classes:

Unstyled list: .list-unstyled removes default list styling.

Inline list: .list-inline displays list items in a single line.

Example:

<ul class="list-unstyled">

  <li>Unstyled list item 1</li>

  <li>Unstyled list item 2</li>

</ul>

<ul class="list-inline">

  <li class="list-inline-item">Inline item 1</li>

  <li class="list-inline-item">Inline item 2</li>

</ul>

Conclusion

A robust and user-friendly typographic system is offered by Bootstrap 5, guaranteeing that your text will be consistently designed and responsive on all devices. You can rapidly add elegant typography to your online projects by using Bootstrap's utility classes for headings, paragraphs, alignment, and colors.

You may improve the readability and aesthetic appeal of your website and make sure that your content looks fantastic on all devices by utilizing Bootstrap's typography tools.