Skip to content

Bootstrap Typography

Bootstrap 5 provides a solid foundation for typography, ensuring consistent and readable text across devices. It sets global defaults and offers utility classes for further customization.

Bootstrap 5 sets a global default font-size of 1rem (typically 16px in most browsers) and a line-height of 1.5.

These defaults are applied to the <body> element and inherited by paragraphs and other text elements.

All <p> elements have a default margin-bottom: 1rem.

Bootstrap 5 also implements Responsive Font Sizes (RFS) by default for headings, allowing text to scale more naturally across device sizes. Learn more at https://getbootstrap.com/docs/5.3/content/typography/#responsive-font-sizes

Bootstrap styles HTML headings (<h1> to <h6>) with specific font sizes, margins, and weights. With RFS, these sizes adapt to the viewport.

<!-- Example display of headings (actual size depends on RFS and viewport) -->
<h1>h1. Bootstrap heading (Approx. 2.5rem)</h1>
<h2>h2. Bootstrap heading (Approx. 2rem)</h2>
<h3>h3. Bootstrap heading (Approx. 1.75rem)</h3>
<h4>h4. Bootstrap heading (Approx. 1.5rem)</h4>
<h5>h5. Bootstrap heading (Approx. 1.25rem)</h5>
<h6>h6. Bootstrap heading (Approx. 1rem)</h6>

Display Headings: For larger, more opinionated heading styles, use display heading classes like .display-1 through .display-6.

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

Bootstrap provides styling for common inline HTML elements:

<small>: For de-emphasized text, often used as secondary text in headings or fine print. It sets the font size to 87.5% of the parent’s.

<h1>Main Heading <small class="text-muted">Secondary text</small></h1>
<p>This is normal text, and this is <small>small text</small>.</p>

<mark> or .mark: Highlights text with a background color (typically yellow).

<p>Use the <mark>mark element</mark> or <span class="mark">.mark class</span> to highlight text.</p>

<abbr>: For abbreviations and acronyms. Bootstrap styles it with a dotted bottom border and a help cursor on hover, revealing the full text from the title attribute.

<p><abbr title="World Health Organization">WHO</abbr> was founded in 1948.</p>
<p><abbr title="HyperText Markup Language" class="initialism">HTML</abbr> is a markup language.</p>
<!-- `.initialism` class makes the <abbr> text slightly smaller. -->

For quoting blocks of content from another source, wrap <blockquote class="blockquote">. For attribution, use a <figcaption class="blockquote-footer">.

<figure class="mb-4">
<blockquote class="blockquote">
<p>A well-known quote, contained in a blockquote element.</p>
</blockquote>
<figcaption class="blockquote-footer">
Someone famous in <cite title="Source Title">Source Title</cite>
</figcaption>
</figure>
<!-- Note: The older `.blockquote-reverse` class is removed. Use text alignment utilities like `.text-end` on the `<figure>` or `<blockquote>` for right-aligned quotes. -->

Bootstrap styles <dl>, <dt>, and <dd> elements. For a horizontal layout where terms and descriptions are side-by-side, use Bootstrap’s grid system or flex utilities.

<!-- Default stacked layout -->
<dl>
<dt>Coffee</dt>
<dd>- black hot drink</dd>
<dt>Milk</dt>
<dd>- white cold drink</dd>
</dl>
<!-- Horizontal layout using grid -->
<dl class="row">
<dt class="col-sm-3">Description lists</dt>
<dd class="col-sm-9">A description list is perfect for defining terms.</dd>
<dt class="col-sm-3">Term</dt>
<dd class="col-sm-9">
<p>Definition for the term.</p>
<p>And some more placeholder definition text.</p>
</dd>
<dt class="col-sm-3 text-truncate">Long truncated term is truncated</dt>
<dd class="col-sm-9">This can be useful when space is limited. Lorem ipsum dolor sit amet, consectetur adipiscing elit.</dd>
</dl>
<!-- Tip: The class `.dl-horizontal` from older Bootstrap versions is removed. The grid system offers more flexibility. -->

: Wrap inline snippets of code with . HTML angle brackets will be escaped.

<p>For example, `&lt;section&gt;` should be wrapped as inline.</p>

<kbd>: Indicates user input that is typically entered via keyboard.

<p>To switch directories, type <kbd>cd</kbd> followed by the name of the directory.<br>
To edit settings, press <kbd><kbd>ctrl</kbd> + <kbd>,</kbd></kbd></p>

<pre>: For multiple lines of code. Escape angle brackets for proper rendering. Consider using the .pre-scrollable class for scrollable blocks.

<pre>`&lt;p&gt;Sample text here...&lt;/p&gt;
&lt;p&gt;And another line of sample text here...&lt;/p&gt;`</pre>
<pre class="pre-scrollable">`// This is a long line of code that will make the pre tag scrollable if it exceeds the width.
// And many more lines...
// ...
// ...
// ... (repeat for many lines to demonstrate scrollability)
`</pre>

Bootstrap provides contextual text color and background utility classes to convey meaning through color. These align with the button and alert color schemes.

Text color classes: .text-primary, .text-secondary, .text-success, .text-info, .text-warning, .text-danger, .text-light, .text-dark, .text-body (default), .text-muted, .text-black-50, .text-white-50.

<p class="text-primary">.text-primary: Primary text for emphasis.</p>
<p class="text-success">.text-success: Indicates a successful action.</p>
<p class="text-danger">.text-danger: Indicates a dangerous action.</p>
<p class="text-muted">.text-muted: Muted text for less emphasis.</p>

Background color classes: .bg-primary, .bg-secondary, .bg-success, etc. These set the background color. Text color might need to be adjusted for contrast (e.g., using .text-white on .bg-dark). Bootstrap 5 also offers combined text and background color utilities like .text-bg-primary.

<div class="p-3 mb-2 bg-primary text-white">.bg-primary .text-white</div>
<div class="p-3 mb-2 bg-success text-white">.bg-success .text-white</div>
<div class="p-3 mb-2 bg-warning text-dark">.bg-warning .text-dark</div>
<div class="p-3 mb-2 text-bg-danger">.text-bg-danger (Combined class)</div>
<!-- Tip: Use `.text-dark` or `.text-white` to ensure contrast on colored backgrounds. -->

Application Scenario: Contextual colors are vital for user feedback, highlighting important information, or styling status indicators.

Bootstrap includes many utility classes for quickly styling text.

ClassDescription
.leadMakes a paragraph stand out (larger font size, lighter weight).
.smallCreates smaller text (87.5% of parent’s font size).
.text-startLeft-aligns text (or start-aligns in LTR, end-aligns in RTL). Replaces .text-left.
.text-centerCenter-aligns text.
.text-endRight-aligns text (or end-aligns in LTR, start-aligns in RTL). Replaces .text-right.
.text-justifyJustifies text.
.text-wrapAllows text to wrap (default behavior).
.text-nowrapPrevents text from wrapping.
.text-breakPrevents long strings of text from breaking your layout by allowing words to break.
.text-lowercaseTransforms text to lowercase.
.text-uppercaseTransforms text to uppercase.
.text-capitalizeCapitalizes the first letter of each word.
.fst-italicStyles text as italic. Replaces .font-italic.
.fst-normalResets text to normal font style.
.fw-boldSets font weight to bold. Replaces .font-weight-bold.
.fw-bolderSets font weight to bolder (relative to parent).
.fw-semiboldSets font weight to semibold.
.fw-normalSets font weight to normal.
.fw-lightSets font weight to light.
.fw-lighterSets font weight to lighter (relative to parent).
.lh-1, .lh-sm, .lh-base, .lh-lgAdjusts line height.
.text-decoration-noneRemoves text decoration (e.g., underlines from links).
.text-decoration-underlineAdds an underline to text.
.text-decoration-line-throughAdds a line-through to text.
.text-resetResets the color of a text or link element to its parent’s color.
.list-unstyledRemoves default list styling (bullets/numbers) and left margin from <ul> or <ol>.
.list-inlineStyles list items to display inline (display: inline-block) with some padding.
.list-inline-itemClass to be applied to each <li> when using .list-inline.

For a complete reference of all typography and text utility classes, consult the official Bootstrap 5 documentation: