Bootstrap 4 Text/Typography

Welcome to The Coding College! In this tutorial, we’ll explore Bootstrap 4 Typography, a powerful set of classes for styling text effortlessly. From headings and paragraphs to alignment and utilities, Bootstrap 4 simplifies the process of creating beautiful and responsive text styles.

By the end of this article, you’ll be equipped to use Bootstrap typography classes effectively in your web projects.

What is Bootstrap 4 Typography?

Bootstrap 4 Typography refers to a collection of classes that control the appearance, alignment, and responsiveness of text. It includes predefined styles for headings, paragraphs, text alignment, display classes, and more.

Typography in Bootstrap 4 is responsive by default, meaning your text will adapt to various screen sizes without additional effort.

Bootstrap 4 Typography Components

Here’s a breakdown of the most common typography features in Bootstrap 4:

1. Headings

Bootstrap provides predefined heading styles (<h1> to <h6>) with consistent font sizes and spacing.

<h1>Bootstrap Heading 1</h1>  
<h2>Bootstrap Heading 2</h2>  
<h3>Bootstrap Heading 3</h3>  
<h4>Bootstrap Heading 4</h4>  
<h5>Bootstrap Heading 5</h5>  
<h6>Bootstrap Heading 6</h6>  

Tip: Add .display-* classes for larger, more prominent headings.

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

2. Paragraphs

Bootstrap provides consistent spacing and font styles for paragraphs.

<p>This is a standard paragraph in Bootstrap 4.</p>  
<p class="lead">This is a lead paragraph with emphasis.</p>  

The .lead class highlights important text by increasing its font size and line spacing.

3. Text Alignment

Align text using .text-left, .text-center, .text-right, or .text-justify.

<p class="text-left">Left-aligned text.</p>  
<p class="text-center">Center-aligned text.</p>  
<p class="text-right">Right-aligned text.</p>  
<p class="text-justify">Justified text spans the entire line.</p>  

You can also use responsive alignment classes like .text-md-center to align text at specific breakpoints.

4. Text Transform

Control capitalization with .text-lowercase, .text-uppercase, or .text-capitalize.

<p class="text-lowercase">this text is lowercase.</p>  
<p class="text-uppercase">this text is uppercase.</p>  
<p class="text-capitalize">capitalize each word in this sentence.</p>  

5. Font Weight and Italics

Bootstrap includes utility classes to adjust font weight and style:

  • .font-weight-bold: Bold text
  • .font-weight-normal: Normal weight text
  • .font-weight-light: Light-weight text
  • .font-italic: Italicized text
<p class="font-weight-bold">Bold text example.</p>  
<p class="font-weight-light">Light text example.</p>  
<p class="font-italic">Italicized text example.</p>  

6. Text Colors

Change text color using Bootstrap’s color utility classes:

<p class="text-primary">Primary color text.</p>  
<p class="text-secondary">Secondary color text.</p>  
<p class="text-success">Success color text.</p>  
<p class="text-danger">Danger color text.</p>  
<p class="text-warning">Warning color text.</p>  
<p class="text-info">Info color text.</p>  
<p class="text-dark">Dark color text.</p>  
<p class="text-muted">Muted text.</p>  
<p class="text-white bg-dark">White text on a dark background.</p>  

7. Blockquotes

Blockquotes are used to highlight quotations. Add the .blockquote class for styling:

<blockquote class="blockquote">  
    <p>"This is a blockquote example."</p>  
    <footer class="blockquote-footer">Author Name</footer>  
</blockquote>  

8. Lists

Bootstrap 4 supports ordered, unordered, and inline lists with additional styling options.

Unordered List:

<ul class="list-unstyled">  
    <li>Item 1</li>  
    <li>Item 2</li>  
    <li>Item 3</li>  
</ul>  

Inline List:

<ul class="list-inline">  
    <li class="list-inline-item">Item 1</li>  
    <li class="list-inline-item">Item 2</li>  
    <li class="list-inline-item">Item 3</li>  
</ul>  

9. Abbreviations

Bootstrap offers a simple way to style abbreviations using the <abbr> tag with the .initialism class.

<p>The abbreviation for HyperText Markup Language is <abbr title="HyperText Markup Language" class="initialism">HTML</abbr>.</p>  

10. Responsive Font Sizes

Bootstrap 4 automatically adjusts font sizes for various screen sizes. Use classes like .h1, .h2, etc., for better responsive design.

Practical Example: Bootstrap 4 Typography

<!DOCTYPE html>  
<html lang="en">  
<head>  
    <meta charset="UTF-8">  
    <meta name="viewport" content="width=device-width, initial-scale=1.0">  
    <title>Bootstrap 4 Typography</title>  
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">  
</head>  
<body>  
    <div class="container">  
        <h1 class="display-1 text-center text-primary">Welcome to Bootstrap 4 Typography</h1>  
        <p class="lead text-justify">This is a lead paragraph, perfect for grabbing attention and summarizing the content of your page.</p>  
        <blockquote class="blockquote text-right">  
            <p>"Bootstrap makes web development faster and easier."</p>  
            <footer class="blockquote-footer">A Web Developer</footer>  
        </blockquote>  
        <p class="text-muted">This is muted text, ideal for less important content.</p>  
        <ul class="list-inline">  
            <li class="list-inline-item text-success">Item 1</li>  
            <li class="list-inline-item text-warning">Item 2</li>  
            <li class="list-inline-item text-danger">Item 3</li>  
        </ul>  
    </div>  
</body>  
</html>  

Best Practices for Bootstrap 4 Typography

  1. Use Utility Classes: Maximize the use of predefined utility classes to save time.
  2. Ensure Readability: Use appropriate font sizes and colors for accessibility.
  3. Combine Classes: Combine typography classes with other Bootstrap components for cohesive designs.
  4. Test Responsiveness: Always test how your text appears across devices and screen sizes.

Learn More with The Coding College

At The Coding College, we’re here to help you master the art of web development. Bootstrap 4 typography simplifies text styling and makes your projects more professional and responsive.

Visit our website for more tutorials, tips, and tricks to enhance your coding skills.

Leave a Comment