Bootstrap Typography
This lesson will teach you how to use Bootstrap to style and structure text content including headers, paragraph, blockquotes, and more.
Working with Headings
In Bootstrap, defining HTML headings (from <h1>
to <h6>
) is as straightforward as in a regular HTML document. Moreover, you have the option to apply heading styles to other elements using the heading classes .h1
through .h6
if desired.
h1. Headings
h2. Headings
h3. Headings
h4. Headings
h5. Headings
h6. Headings
Customizing Headings
To display secondary text for any heading in a smaller and lighter variation, you can use the <small>
tag along with the .text-muted
class. Here's an example:
Great show heading
the secondary text is fading
Display Headings
Bootstrap also offers display headings that are useful when you want a heading to stand out. Display headings are presented in a larger font size but with a lighter font weight.
There are six different display headings available. Here's an example:
Show Headings
Show Headings
Show Headings
Show Headings
Show Headings
Show Headings
Working with Paragraphs
Bootstrap's default global font-size
is 1rem (typically 16px), and its line-height
is 1.5 (typically 24px), which is applied to both the <body>
element and all <p>
elements (paragraphs). Additionally, a margin-bottom
of 1rem is applied to all paragraphs.
You can make a paragraph stand out by adding the .lead
class to it.
A typical sentence in Bootstrap look like this.
A typical sentence in Bootstrap look like this.
Tip: In CSS, rem stands for root em, and 1rem is equal to the font size of the root element (i.e., the <html>
element), which is usually 16px in most browsers by default.
Text Alignment
Text alignment can be easily achieved in Bootstrap using classes for left, right, and center alignment.
Left In all viewing sizes, the content is aligned.
Center In all viewing sizes, the content is aligned.
Right In all viewing sizes, the content is aligned.
Moreover, Bootstrap provides responsive text alignment classes that allow you to align text based on screen size, using the same viewport width breakpoints as the grid system.
Up to and including small size (sm) viewports, content will be centered.
For medium-sized (md) viewports and larger, content will be centered.
In large viewports (lg) and larger, content will be centered aligned.
In extra-large (xl) viewports and larger, content will be center aligned.
Text Formatting
You are free to use text formatting tags like <strong>
, <i>
, and <small>
to apply styles like bold, italic, and small, just as you would in a simple HTML page. Here's an example:
This text is bold
Code for a computer
This text is highlighted.
This text is bold.
The highlighted text here
Little text here
Strong text emphasis is used here
This is subscripts and superscripts
The document includes this content.
The document has been updated to remove this text.
Text Transformation
Additionally, you have the option to transform text in Bootstrap by converting it to lowercase, uppercase, or capitalize the first letter.
I will win definitely but not immediately.
I will win definitely but not immediately.
I will win definitely but not immediately.
Text Coloring
Colors play a crucial role in conveying important information in website design.
Bootstrap provides a variety of emphasis utility classes that can be utilized for specific purposes, such as displaying success messages in green color or warning/error messages in red color, among others.
Primary:Before continuing, please read the instructions.
Secondary: The most recent version no longer includes this functionality.
Success: Your message was successfully delivered.
Info:To finish the sign-up procedure, you must accept the terms and conditions.
Warning: The network connection you were using had an issue.
Danger:During sending your data, a mistake was made.
Muted: This sentence has a grayed-out background.
For a comprehensive understanding of text coloring, background coloring classes, and various other utility classes, refer to the Bootstrap helper classes chapter.
Styling Blockquotes
To enhance the appearance of your blockquotes, you can easily define them using the standard <blockquote>
element, and Bootstrap's style sheet will take care of the rest.
Knowledge is not as vital as imaginations.
When attributing quotes, enclose your <blockquote>
in a <figure>
element and use a <figcaption>
or a block-level element (e.g., <p>
) with the .blockquote-footer
class.
You can also align blockquotes to the right or center by applying the text alignment classes .text-end
or .text-center
to the <blockquote>
or <figure>
element.
Truncating Long Text
If you have longer text that needs to be displayed in a single line but there isn't enough space available, you can use the .text-truncate
class to truncate the text with an ellipsis. However, it's important to note that the display
property value of the element must be set to inline-block
or block
for this to work correctly.
This feature becomes especially useful when you want to showcase condensed text without compromising on readability. Let's experiment with an example to see how it functions in action.
I will win definitely but not immediately.
I will win definitely but not immediately.
Text wrapping and Overflow
The class .text-wrap
can be utilized to wrap text within an element by overriding its white-space
property, especially when it is set to pre
or nowrap
, like in Bootstrap badge components.
Similarly, by using the class .text-nowrap,
you can stop text from wrapping within an element.
Let's test the following example to grasp its fundamental functionality:
This text will wrap.
The content will fill the whole box of the elements.
Wrapping Long Word
To prevent long words from disrupting your layout, you can use the class .text-break
.
veryveryveryveryveryveryverylongword
FAQ
What is Bootstrap Typography?
Bootstrap Typography refers to the system of organizing and styling text content in a consistent and visually appealing manner using the Bootstrap framework. It includes a set of CSS classes and styles that help developers create headings, paragraphs, lists, and other textual elements with predefined styles.
How do you create headings using Bootstrap Typography?
To create headings using Bootstrap Typography, you can use the <h1>
to <h6>
HTML elements along with Bootstrap's corresponding classes. For example, to create a large and bold heading, you can use the class class="h1"
for an <h1>
element. This applies the appropriate font size and weight styles.
Heading 1
Heading 2
What are display headings in Bootstrap?
Display headings are extra-large and bold headings designed to grab the user's attention. They are created using the display-{1-6}
classes. These classes increase the font size and weight of the headings to make them stand out.
Large Heading
How can you style paragraphs with Bootstrap Typography?
You can style paragraphs using the default Bootstrap classes for text. For instance, you can use the class class="lead"
on a paragraph to make it larger and stand out, often used for introductory content or summaries.
This text is emphasized for importance.
What is the purpose of Bootstrap's utility classes for text manipulation?
Bootstrap provides utility classes that allow you to quickly modify the appearance of text. These classes include text alignment (text-left
, text-center
, text-right
, text-justify
), text transformation (text-uppercase
, text-lowercase
, text-capitalize
), and font weight (font-weight-bold
, font-weight-normal
, etc.).
How can you create lists with Bootstrap Typography?
You can create ordered and unordered lists using the HTML <ul>
and <ol>
elements, respectively. To style these lists, Bootstrap provides classes like list-unstyled
to remove default list styling and list-inline
to create horizontal inline lists.
- Item 1
- Item 2
- Item 1
- Item 2
What is the purpose of the blockquote
class in Bootstrap Typography?
The blockquote
class is used to style blockquote elements, which are often used to highlight quoted content or testimonials on a webpage. The class adds appropriate margins and styles to enhance the visual presentation of blockquotes.
This is a blockquote.
How can you handle text alignment in Bootstrap Typography?
Bootstrap offers text alignment classes such as text-left
, text-center
, text-right
, and text-justify
. These classes allow you to align your text content as needed within different containers.
Left-aligned text.
Centered text.
Right-aligned text.
Justified text.
What is the purpose of the display-4
class in Bootstrap Typography?
The display-4
class is used to create the largest and most prominent display heading (usually <h1>
). It increases the font size and weight of the text, making it suitable for important page titles or headers.
This text is emphasized for importance.
How can you customize font sizes using Bootstrap Typography?
Bootstrap provides responsive font size classes such as fs-1
to fs-6
that allow you to adjust font sizes based on the screen size. These classes ensure that text remains legible on various devices.
Font Size 1 (Larger Text)
Font Size 6 (Smaller Text)
How can you create emphasized or highlighted text using Bootstrap?
Bootstrap provides the <mark>
HTML element and the class mark
to create highlighted or emphasized text. This is often used to draw attention to specific words or phrases within a paragraph.
This is a highlighted word. It's also smaller.
What is the purpose of the text-muted
class in Bootstrap Typography?
The text-muted
class is used to apply a light gray color to text, indicating that it's less important or subdued. It's often used for metadata, captions, or text that doesn't require immediate attention.
How can you create responsive text in Bootstrap Typography?
Bootstrap's responsive text classes like text-sm
, text-md
, text-lg
, and text-xl
allow you to adjust text size based on different breakpoints. This ensures that text remains readable and appropriately sized across various screen sizes.
Large text on larger screens.
What is the purpose of the text-truncate
class in Bootstrap Typography?
The text-truncate
class is used to truncate text that exceeds the width of its container with an ellipsis. This is useful when you have limited space and want to indicate that there's more content.
This is a long text that gets truncated with an ellipsis.
How can you create text with a primary or contextual color in Bootstrap Typography?
Bootstrap offers contextual text color classes such as text-primary
, text-success
, text-info
, text-warning
, and text-danger
. Applying these classes changes the color of the text to match the associated contextual color.
Primary-colored text
What is the purpose of the text-decoration
class in Bootstrap Typography?
The text-decoration
class provides options for styling text decorations, such as underlines, overlines, and line-throughs. For example, you can use text-decoration-underline
to underline text.
How can you create responsive font-weight using Bootstrap Typography?
Bootstrap's responsive font-weight classes like fw-light
, fw-normal
, fw-bold
, and fw-bolder
allow you to adjust font weights based on different breakpoints.
Bold text
What is the purpose of the text-break
class in Bootstrap Typography?
The text-break
class is used to allow long words and URLs to wrap and break onto the next line, preventing horizontal overflow within their container.
ThisIsALongURLThatWrapsAndBreaks
What is the purpose of the text-nowrap
class in Bootstrap Typography?
The text-nowrap
class prevents text from wrapping to the next line, ensuring that it remains on a single line within its container.
This text won't wrap.
How can you adjust the letter spacing of text using Bootstrap Typography?
Bootstrap provides classes like tracking-tighter
, tracking-tight
, tracking-normal
, tracking-wide
, and tracking-wider
to adjust the letter spacing of text.
How can you create justified text using Bootstrap Typography?
Bootstrap's text-justify
class is used to create justified text, where both the left and right edges are aligned. This provides a clean and structured appearance to paragraphs.
How can you vertically align text using Bootstrap Typography?
Bootstrap offers vertical alignment classes like align-baseline
, align-top
, align-middle
, align-bottom
, and align-text-top
, align-text-bottom
to control the vertical alignment of text within its containing element.
What is the purpose of the text-shadow
class in Bootstrap Typography?
The text-shadow
class is used to apply shadow effects to text. You can use it to create a subtle or bold shadow behind the text for a visual effect.
Conclusion
Bootstrap provides a robust set of tools and classes for text styling and typography that empower web designers and developers to create visually appealing and user-friendly content. The framework offers extensive options for font styles, text formatting, and customizing text appearance, allowing for responsive text design that caters to a wide range of devices and screen sizes.
With font properties and font classes, Bootstrap offers typography options that cover text elements, ensuring that your content remains readable text that adheres to consistent text alignment and offers various heading styles for a harmonious layout. Bootstrap's commitment to responsive font design enables you to control typeface and their alignment, ensuring that your paragraph styles, and manage text size and color, allowing for responsive typography that responds to different screen sizes.
Furthermore, Bootstrap provides tools to control text alignment, wrapping, and overflow, as well as text transformation effects and truncation. This flexibility allows for typeface customization and adjustable font size and color, ensuring that your text layout and alignment meet your design goals.
You can effectively manage text wrapping and overflow, explore text transformation options, and fine-tune font weight and style, all while maintaining appropriate line height and spacing.