Text
Documentation and examples for common text utilities to control alignment, wrapping, weight, and more.
Text alignment#
Easily realign text to components with text alignment classes.
<p class="text-justify">Ambitioni dedisse scripsisse iudicaretur. Cras mattis iudicium purus sit amet fermentum. Donec sed odio operae, eu vulputate felis rhoncus. Praeterea iter est quasdam res quas ex communi. At nos hinc posthac, sitientis piros Afros. Petierunt uti sibi concilium totius Galliae in diem certam indicere. Cras mattis iudicium purus sit amet fermentum.</p>
For left, right, and center alignment, responsive classes are available that use the same viewport width breakpoints as the grid system.
<p class="text-left">Left aligned text on all viewport sizes.</p>
<p class="text-center">Center aligned text on all viewport sizes.</p>
<p class="text-right">Right aligned text on all viewport sizes.</p>
<p class="text-sm-left">Left aligned text on viewports sized SM (small) or wider.</p>
<p class="text-md-left">Left aligned text on viewports sized MD (medium) or wider.</p>
<p class="text-lg-left">Left aligned text on viewports sized LG (large) or wider.</p>
Text wrapping and overflow#
Wrap text with a .text-wrap
class.
<div class="badge badge-primary text-wrap" style="width:6rem">This text should wrap.</div>
Prevent text from wrapping with a .text-nowrap
class.
<div class="text-nowrap bd-highlight" style="width: 8rem;">
This text should overflow the parent.
</div>
For longer content, you can add a .text-truncate
class to truncate the text with an ellipsis. Requires display: inline-block
or display: block
.
<div class="row">
<div class="col-2 text-truncate">
Praeterea iter est quasdam res quas ex communi.
</div>
</div>
<span class="d-inline-block text-truncate" style="max-width: 150px;">
Praeterea iter est quasdam res quas ex communi.
</span>
Word break#
Prevent long strings of text from breaking your components' layout by using .text-break
to set overflow-wrap: break-word
(and word-break: break-word
for IE & Edge compatibility).
<p class="text-break">
mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm
</p>
Word separation#
To optimise your space used by text, you can add the class .hyphens
. This class make sure your words break right or at least they don't break the wrapping container.
Be sure to use the right language. If the language of the text don't match the language of the site, add the lang
attribute to the container of the text.
As an alternative you can use ­
as an additional breakpoint in a word on content level.
If the browser don't support hyphens: auto;
the property overflow-wrap: break-word;
reacts as an fallback, so the words be broken at arbitrary points, if there are no otherwise acceptable break points in the line.
The three boxes have the same text. The first one is only the raw text, the second is with the class .hyphens
and the last one is with ­
, seen here:
Ses­qui­pe­da­lian­ism is a common prob­lem on small el­e­ments. There is no need for Floc­cin­aucini­hilipil­i­fi­ca­tion on this subject.
Take care of word sep­a­ra­tion over multiple lines to not generate In­com­pre­hen­si­bili­ties.
This text is un­copy­right­able, ev­ery­thing else were Un­imag­i­na­tive­ly.
<div class="table-responsive">
<table class="table">
<thead>
<tr>
<th>
</th>
<th>Normal</th>
<th>Hyphens (.hyphens)</th>
<th>Shy (­)</th>
</tr>
</thead>
<tbody>
<tr>
<th>wide</th>
<td>
<p class="border">Sesquipedalianism is a common problem on small elements. There
is no need for Floccinaucinihilipilification on this subject. Take care of
word separation over multiple lines to not generate Incomprehensibilities.
This text is uncopyrightable, everything else were Unimaginatively.</p>
</td>
<td>
<p class="border hyphens" lang="en-GB">Sesquipedalianism is a common problem on
small elements. There is no need for Floccinaucinihilipilification on this
subject. Take care of word separation over multiple lines to not generate
Incomprehensibilities. This text is uncopyrightable, everything else were
Unimaginatively.</p>
</td>
<td>
<p class="border">Sesquipedalianism is a common problem on small
elements. There is no need for Floccinaucinihilipilification on
this subject. Take care of word separation over multiple lines to not
generate Incomprehensibilities. This text is uncopyrightable,
everything else were Unimaginatively.</p>
</td>
</tr>
<tr>
<th>narrow</th>
<td>
<p class="border" style="width:100px">Sesquipedalianism is a common problem on
small elements. There is no need for Floccinaucinihilipilification on this
subject. Take care of word separation over multiple lines to not generate
Incomprehensibilities. This text is uncopyrightable, everything else were
Unimaginatively.</p>
</td>
<td>
<p class="border hyphens" style="width:100px" lang="en-GB">Sesquipedalianism is
a common problem on small elements. There is no need for
Floccinaucinihilipilification on this subject. Take care of word separation
over multiple lines to not generate Incomprehensibilities. This text is
uncopyrightable, everything else were Unimaginatively.</p>
</td>
<td>
<p class="border" style="width:100px">Sesquipedalianism is a common
problem on small elements. There is no need for
Floccinaucinihilipilification on this subject. Take care of word
separation over multiple lines to not generate
Incomprehensibilities. This text is uncopyrightable, everything
else were Unimaginatively.</p>
</td>
</tr>
</tbody>
</table>
</div>
Text transform#
Transform text in components with text capitalization classes.
<p class="text-lowercase">Lowercased text.</p>
<p class="text-uppercase">Uppercased text.</p>
<p class="text-capitalize">CapiTaliZed text.</p>
Note how .text-capitalize
only changes the first letter of each word, leaving the case of any other letters unaffected.
Font weight and italics#
Quickly change the weight (boldness) of text or italicize text.
<p class="font-weight-bold">Bold text.</p>
<p class="font-weight-bolder">Bolder weight text (relative to the parent element).</p>
<p class="font-weight-normal">Normal weight text.</p>
<p class="font-weight-light">Light weight text.</p>
<p class="font-weight-lighter">Lighter weight text (relative to the parent element).</p>
<p class="font-italic">Italic text.</p>
Monospace#
Change a selection to our monospace font stack with .text-monospace
.
<p class="text-monospace">This is in monospace</p>
Reset color#
Reset a text or link's color with .text-reset
, so that it inherits the color from its parent.
<p class="text-muted">Muted text with a <a href="#" class="text-reset">reset link</a>.</p>
Text decoration#
Remove a text decoration with a .text-decoration-none
class.
<a href="#" class="text-decoration-none">Non-underlined link</a>
Font sizes#
Use a specific font size. In most cases it will be used in content sections. Instead of <small>
or .small
with percentage sizes the .text-sm
and .text-lg
uses specific font sizes.
Default for .text-sm
is 0.75rem
(12px) for mobile screens and 0.875rem
(14px) for lg breakpoint.
Default for .text-lg
is 1.25rem
(20px) for mobile screens and 1.375rem
(22px) for lg breakpoint.
<p class="text-sm">Small text.</p>
<p class="text-lg">Large text.</p>