Welcome to our comprehensive guide on Bootstrap 5 Typography! In this tutorial, we'll dive deep into the world of text styling using Bootstrap 5, a popular open-source CSS framework. By the end of this lesson, you'll be able to create beautiful, responsive typography for your web projects. š
Before we begin, let's make sure you have Bootstrap 5 installed in your project. You can find installation instructions here.
Bootstrap 5 comes with a variety of predefined classes for common typographic styles. Let's explore some of them:
Bootstrap 5 offers six levels of headings from h1 to h6. Each heading level corresponds to a larger and bolder font size.
<h1>h1 Heading</h1>
<h2>h2 Heading</h2>
<h3>h3 Heading</h3>
<h4>h4 Heading</h4>
<h5>h5 Heading</h5>
<h6>h6 Heading</h6>The default paragraph style in Bootstrap 5 is .fs-normal which applies the font-size: 1rem to the text.
<p class="fs-normal">This is a paragraph.</p>Lead text is used for secondary headings or headings in lists. In Bootstrap 5, lead text has a font-size: 1.25rem and is slightly smaller than the h2 heading.
<h2>Main Heading</h2>
<p class="fs-lead">This is lead text.</p>Display text is used for large headings or headings that require extra emphasis. In Bootstrap 5, display text has a font-size: 2.25rem and is larger than the h1 heading.
<h1>Main Heading</h1>
<p class="display-4">This is display text.</p>Bootstrap 5 also provides various classes for styling text, such as text color, text alignment, and text transform.
To change the text color, you can use the predefined text utility classes. For example:
<p class="text-primary">This is primary text.</p>
<p class="text-secondary">This is secondary text.</p>To align text, you can use the predefined text-align utility classes. For example:
<p class="text-start">This text is aligned to the start.</p>
<p class="text-center">This text is centered.</p>
<p class="text-end">This text is aligned to the end.</p>To change the text case, you can use the predefined text-transform utility classes. For example:
<p class="text-uppercase">This text is uppercase.</p>
<p class="text-lowercase">This text is lowercase.</p>
<p class="text-capitalize">This text has only the first letter capitalized.</p>Bootstrap 5's responsive grid system allows you to create responsive typography easily. You can use the col classes to control the number of columns a heading or paragraph spans across different screen sizes.
For example, to create a two-column layout for medium and large screens, you can use the following markup:
<div class="row">
<div class="col-md-6">
<h1>Column 1</h1>
<p>This is column 1.</p>
</div>
<div class="col-md-6">
<h1>Column 2</h1>
<p>This is column 2.</p>
</div>
</div>You can also create your own custom typography styles using Bootstrap 5's custom utility classes. For example:
<p class="fw-bold">This text is bold.</p>
<p class="fs-5">This text has a font size of 0.875rem.</p>Which class is used to change the text color in Bootstrap 5?
We hope you enjoyed this comprehensive guide on Bootstrap 5 Typography. By now, you should have a solid understanding of how to style text in Bootstrap 5. Keep practicing, and soon you'll be creating beautiful, responsive typography for your web projects. Happy coding! š
š Note: This tutorial is just a starting point for you. Explore the Bootstrap 5 documentation for more details and advanced features.