Bootstrap 5 provides several font weight classes that you can use to control the weight of text elements on your web page. These classes allow you to easily apply different font weights to your HTML elements, such as headings, paragraphs, and other text elements. The following are some commonly used font weight classes:
Class | Font Weight | Description |
---|---|---|
.fw-lighter | Lighter | Sets the font weight to a lighter value |
.fw-light | Light (300) | Sets the font weight to "light" |
.fw-normal | Normal (400) | Sets the font weight to "normal" |
.fw-medium | Medium (500) | Sets the font weight to "medium" |
.fw-semibold | Semibold (600) | Sets the font weight to "semibold" |
.fw-bold | Bold (700) | Sets the font weight to "bold" |
.fw-bolder | Bolder | Sets the font weight to a bolder value |
You can use these classes with HTML elements in your projects to control the font weight and achieve the desired typographic styles. Let's explain each of the font weight classes:
.fw-lighter
: This class sets the font weight to a lighter value than the parent element. It is useful when you want to reduce the thickness of the text to create a delicate and elegant appearance. The exact font weight value depends on the font family and the default "lighter" weight available in the chosen font..fw-light
: The.fw-light
class sets the font weight to a light value (typically around 300). It makes the text thinner than the normal weight and is suitable for content where you want a lighter appearance without being as subtle as.fw-lighter
..fw-normal
: This is the default font weight class. It sets the font weight to "normal" (typically around 400). Use this class for regular body text, paragraphs, and other content where you don't need any specific emphasis on font weight..fw-medium
: The.fw-medium
class sets the font weight to a medium value, usually around 500. It offers a slightly heavier weight than the normal font-weight..fw-semibold
: The.fw-semibold
class sets the font weight to a semi-bold value (typically around 600). It offers a stronger emphasis than.fw-medium
but is lighter than.fw-bold
. Use this class when you need a significant emphasis on certain text elements..fw-bold
: The.fw-bold
class sets the font weight to bold (typically around 700). It makes the text thicker and is commonly used for headings, titles, and other important elements that require high visibility and emphasis..fw-bolder
: This class sets the font weight to a bolder value than the parent element. It provides an even stronger emphasis compared to.fw-bold
. However, the exact font weight value depends on the parent element's font weight, which may not be available in all font families.
These font weight classes enable faster development and save time by offering pre-defined styles that eliminate the need for custom CSS. Developers can achieve consistent and appealing typography quickly, allowing more focus on other aspects of the website, resulting in efficient development cycles.
Implementing Font Weight Classes
To apply the desired font weight, simply add the appropriate class to your HTML elements. For example, To create bold text in Bootstrap, you can use the .fw-bold
class. This class sets the font weight of the text to "bold," which is typically represented by a value of 700. Here's an example of how you can use font weight classes to style text elements with different weights:
<div class="fw-lighter mb-3">This text is lighter than the parent element.</div>
<div class="fw-light mb-3">This text is light.</div>
<div class="fw-normal mb-3">This text is normal.</div>
<div class="fw-medium mb-3">This text is medium.</div>
<div class="fw-seminbold mb-3">This text is semibold.</div>
<div class="fw-bold mb-3">This text is bold.</div>
<div class="fw-bolder mb-3">This text is bolder than the parent element.</div>
These classes can be applied to various HTML elements, such as <p>
, <span>
, <a>
, <div>
, etc., to style your text according to your design preferences. Please note that the numerical values (e.g., 300, 400, 700) represent the standard font weight values for most fonts. However, the actual visual appearance may vary depending on the font family used in your project.