HTML Text Formatting
Last Updated :
26 Jun, 2024
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:
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).
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.
| Tags | Descriptions |
|---|
| <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:

HTML Text Formatting Example Output
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:

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.
Please Login to comment...