The Wayback Machine - https://web.archive.org/web/20240707042009/https://www.geeksforgeeks.org/html-text-formatting/
Open In App

HTML Text Formatting

Last Updated : 26 Jun, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

HTML text formatting tags enhance web content’s visual presentation and semantic meaning. By using tags like <b>, <i>, <em>, and <strong>, you can style text as bold, italic, emphasized, or important, improving readability and user experience on webpages.

HTML text formatting can be categorized into two techniques:

1. Logical Tags

These tags denote the logical or semantic value of the text. They convey meaning without directly affecting the visual appearance.

  • <em>: Emphasizes text (commonly styled as italic).
  • <strong>: Indicates important content (often styled as bold).

2. Physical Tags

These tags directly impact the visual appearance of the text, altering font styles, sizes, and other visual properties.

  • <b>: Displays text in a bold format.
  • <i>: Italicizes text.

HTML Formatting Elements

TagsDescriptions
<i>Showcases italicized text.
<small>Renders text in a smaller font size.
<ins>Highlights added or inserted text.
<sub>Creates subscript text.
<strong>Emphasizes text with importance, often in bold.
<b>Displays text in a bold format.
<mark>Accentuates text with a background highlight.
<del>Strikes through text to signify deletion.
<em>Adds emphasis to text, commonly styled as italic.
<sup>Formats text as superscript.

Example of Text Formatting

Example 1: Basic Text Formatting

In this example we demonstrates various text formatting tags: <strong> for important and bold text, <em> for emphasized and italic text, <b> for bold text, <i> for italic text, and <mark> for highlighted text.

HTML
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>Text Formatting Example</title>
</head>

<body>
    <p>
        <strong>Strong:</strong> 
        This text is important and bold.
    </p>
    <p>
        <em>Emphasized:</em> 
        This text is emphasized and italic.
    </p>
    <p>
        <b>Bold:</b> 
        This text is bold.
    </p>
    <p>
        <i>Italic:</i> 
        This text is italic.
    </p>
    <p>
        <mark>Marked:</mark> 
        This text is highlighted.
    </p>
</body>

</html>

Output:

text-formatting

HTML Text Formatting Example Output

Example 2: Combining Logical and Physical Tags

This example shows how logical and physical tags can be combined for enhanced text formatting:

HTML
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>Advanced Text Formatting</title>
</head>

<body>
    <p>This is a 
        <strong><em>very important</em></strong> message.
    </p>
    <p>The chemical formula of water is H
        <sub>2</sub>O.
    </p>
    <p>
        <del>Deleted text</del> and 
        <ins>inserted text</ins> 
        are shown here.
    </p>
    <p><small>Smaller text</small> 
        can be used for disclaimers.
    </p>
    <p>E = mc<sup>2</sup></p>
</body>

</html>

Output:

text-formatting-2

Conclusion

HTML text formatting tags are essential for creating visually appealing and semantically meaningful web content. By using logical tags like <em> and <strong>, you can convey the importance of the content, while physical tags like <b> and <i> allow you to directly alter the appearance of the text. Understanding and utilizing these tags effectively can significantly enhance the readability and user experience of your website.



Previous Article
Next Article

Similar Reads

HTML Text Formatting Elements
As we know, HTML provides many predefined elements that are used to change the formatting of text. The formatting can be used to set the text styles (like - bold, italic, or emphasized, etc.), highlight the text, make text superscript and subscript, etc. Text Formatting Elements: &lt;b&gt; and &lt;strong&gt; Tags: Both tags are used to make text bo
3 min read
Which property is used to control the flow and formatting of text ?
In this article, we will discuss the property that is used to control the flow and formatting of text. The white-space property in CSS is used to control the text wrapping and white-spacing ie., this property can be used to set about the handling of the white-space inside the elements. There are several types of values in this property to use. Synt
2 min read
CSS Text Formatting
CSS Text Formatting refers to applying styles to text elements to control appearance and layout. This includes properties for color, alignment, decoration, indentation, justification, shadows, spacing, and direction. These properties enhance readability and aesthetics, improving the presentation of textual content on web pages. Syntax: The Syntax t
2 min read
JavaScript Text Formatting
JavaScript has many inbuilt features to format the text. Texts are the strings in JavaScript. There are many formatting styles like making text uppercase, lowercase, bold, and italic. Below are several formatting styles in JavaScript which are as follows: Table of Content Making text UpperCaseMaking text LowerCaseUsing SubstrUsing repeatUse of trim
2 min read
What are the various formatting tags available in HTML ?
As we know, HTML provides many predefined elements that are used to change the formatting of text. The formatting can be used to set the text styles (like – bold, italic, or emphasized, etc.), highlight the text, make text superscript and subscript, etc. In this article, we will discuss different formatting tags in HTML. &lt;b&gt; and &lt;strong
3 min read
How to select all text in HTML text input when clicked using JavaScript?
This example shows how to select entire input in a single click using javaScript. Syntax: &lt;input onClick="this.select();" &gt; or document.getElementById("ID").select(); Example-1: Using "this.select()". &lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt; Select all text in HTML text input when clicked &lt;/title&gt; &lt;/head&gt; &lt;
1 min read
How to create long shadow of text without using text-shadow in HTML and CSS ?
Shadows are really a nice way to give depth and 3-D look to any text. Generally, we use text-shadow to give shadow to the text but this shadow is short and to create long shadow (shadow in which text is visible like that of reflection) we have to use before selector and skew function. Approach: The approach is to use a skew to create tilted text fi
2 min read
Text Animation with changing the color of the text using HTML and CSS
Text animation is the creation of beautiful and colorful letters, words, and paragraphs with a decorative movable effect. The movement can be seen in some fashion within the area or across the screen following some regular pattern. The @keyframes in CSS allows defining a series of animations at specific points during an animation sequence. In this
2 min read
Primer CSS General Formatting
Primer CSS is a free open-source CSS framework that is built upon a GitHub design system to provide support to the broad spectrum of GitHub websites. It creates the foundation of the basic style elements such as spacing, typography, and color. This systematic method makes sure our patterns are steady and interoperable with every other. Its approach
3 min read
Role of ViewPort in Visual Formatting Model
In this article, we will see the role of the Viewport in the Visual Formatting Model, along with knowing its purpose &amp; basic implementation. A Browser’s viewport is the area of a web page in which the content is visible to the user. The viewport does not have the same size, it varies with the variation in screen size of the devices on which the
3 min read
three90RightbarBannerImg