Html Text Formatting Tags Complete Guide

 Last Update:2025-06-23T00:00:00     .NET School AI Teacher - SELECT ANY TEXT TO EXPLANATION.    8 mins read      Difficulty-Level: beginner

Understanding the Core Concepts of HTML Text Formatting Tags

HTML Text Formatting Tags: Detailed Explanation and Important Information

  1. and Tags:

    • Usage: <b> is used to make text bold without any semantic meaning, while <strong> indicates that the text is of strong importance.
    • Example: <b>Bold text</b> and <strong>Important Bold Text</strong>
    • Importance: <strong> is more significant for SEO and accessibility, as it conveys extra importance to screen readers.
  2. and Tags:

    • Usage: <i> renders text in italics for stylistic use, whereas <em> stresses the text and is read in a different voice by screen readers.
    • Example: <i>Italic text</i> and <em>Emphasized Text</em>
    • Importance: <em> adds meaning to the text and is beneficial for SEO by highlighting emphasis.
  3. Tag:

    • Usage: <u> underlines text. It’s primarily used for stylistic purposes and doesn’t indicate any semantic importance.
    • Example: <u>Underlined text</u>
    • Importance: In modern web design, <u> is not commonly used due to its stylistic nature and limited semantic meaning. It is generally better to use CSS for underlining.
  4. Tag:

    • Usage: <mark> highlights text for reference or note-taking.
    • Example: <mark>Highlighted text</mark>
    • Importance: This tag is useful for search term highlighting or drawing attention to specific text on a page. It is semantically meaningful.
  5. Tag:

    • Usage: <small> reduces the font size of the text.
    • Example: <small>Small text</small>
    • Importance: It is often used for copyright notices, disclaimers, or footnotes.
  6. and Tags:

    • Usage: <del> indicates text that has been deleted from a document, while <s> is used for stylistic strikethroughs without implying removal.
    • Example: <del>Deleted text</del> and <s>Strikethrough text</s>
    • Importance: <del> has semantic value, signaling a change in context, whereas <s> is more about styling.
  7. Tag:

    • Usage: <ins> is used to mark text that has been inserted into a document.
    • Example: <ins>Inserted text</ins>
    • Importance: This tag adds semantic value by indicating text that has been added, which is useful for comparison and version control.
  8. and Tags:

    • Usage: <sub> renders text as subscripts, while <sup> renders text as superscripts.
    • Example: <sub>Subscript text</sub> and <sup>Superscript text</sup>
    • Importance: These tags are crucial for mathematical, chemical, and bibliographic content where subscripts and superscripts play significant roles.
  9. Tag:

    • Usage: <abbr> is used to define abbreviations or acronyms in the text, providing a title attribute for the full form.
    • Example: <abbr title="World Health Organization">WHO</abbr>
    • Importance: It enhances readability and contributes positively to SEO by providing additional information through the title attribute.
  10. Tag:

    • Usage: <q> is used to display inline quotations within a text.
    • Example: <q>Life is what happens when you're busy making other plans.</q>
    • Importance: It is semantically meaningful for short quotes and assist screen readers in understanding content better.
  11. Tag:

    • Usage: <blockquote> is used to display block-level quotations or longer passages.
    • Example: <blockquote><q>To be, or not to be, that is the question,</q> — Hamlet</blockquote>
    • Importance: This tag is crucial for embedding longer quotes and can include the cite attribute for linking to the source.
  12. and

     Tags:

    • Usage: <code> is used for inline code snippets, while <pre> preserves whitespace and line breaks for preformatted text.
    • Example: <code>function helloWorld() { console.log('Hello, world!'); }</code> and <pre>function helloWorld() {\n console.log('Hello, world!');\n}</pre>
    • Importance: These tags are essential for displaying code correctly, maintaining readability, and preserving code formatting.

Conclusion

Online Code run

🔔 Note: Select your programming language to check or run code at

💻 Run Code Compiler

Step-by-Step Guide: How to Implement HTML Text Formatting Tags

Step 1: Basic HTML Structure

Before we dive into the text formatting tags, let's establish a basic HTML document structure:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>HTML Text Formatting Tags</title>
</head>
<body>
    <!-- Our content will go here -->
</body>
</html>

Step 2: Adding Bold Text

The <b> or <strong> tag can be used to make text bold. Both tags serve a similar purpose, but <strong> is often used for semantically important text that needs emphasis.

Example using <b>:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Bold Text Example</title>
</head>
<body>
    <p>This is a normal paragraph, and here is some <b>bold text</b>.</p>
</body>
</html>

Example using <strong>:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Bold Text with Strong Example</title>
</head>
<body>
    <p>Please read this text carefully. <strong>It is very important!</strong></p>
</body>
</html>

Step 3: Adding Italic Text

The <i> or <em> tag can be used to italicize text. Similar to bold tags, <em> is often preferred for semantically emphasizing the text.

Example using <i>:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Italic Text Example</title>
</head>
<body>
    <p>This is a normal paragraph, and here is some <i>italicized text</i>.</p>
</body>
</html>

Example using <em>:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Italic Text with Emphasis Example</title>
</head>
<body>
    <p>The importance of reading instructions cannot be overstated. <em>Please read before proceeding.</em></p>
</body>
</html>

Step 4: Underlining Text

The <u> tag is used to underline text. Note that underlining is not usually used for emphasis because it might look like a hyperlink.

Example:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Underline Text Example</title>
</head>
<body>
    <p>This is a normal paragraph, and here is some <u>underlined text</u>.</p>
</body>
</html>

Step 5: Striking Through Text

The <s> or <strike> tag can be used to strike through text. The <del> tag indicates that text has been deleted from a document, while the <ins> tag indicates an insertion.

Example using <s>:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Strikethrough Text Example</title>
</head>
<body>
    <p>This offer is no longer valid. Please do not purchase <s>immediately</s>.</p>
</body>
</html>

Example using <del> and <ins>:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Deleted and Inserted Text Example</title>
</head>
<body>
    <p>The book was originally priced at <del>$30</del>, but now it costs <ins>$20</ins>.</p>
</body>
</html>

Step 6: Superscript and Subscript

The <sup> tag represents superscripted text (small text above the normal line), and the <sub> tag represents subscripted text (small text below the normal line).

Example:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Superscript and Subscript Example</title>
</head>
<body>
    <p>Einstein’s famous equation for energy is E=mc<sup>2</sup>.</p>
    <p>The chemical formula for water is H<sub>2</sub>O.</p>
</body>
</html>

Step 7: Small Text

The <small> tag displays text in a smaller font size, often used for disclaimers or copyright notices.

Example:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Small Text Example</title>
</head>
<body>
    <p>Make sure to bring your umbrella today.</p>
    <p><small>Note: This information may change without notice.</small></p>
</body>
</html>

Step 8: Marked Text

The <mark> tag is used to highlight text.

Example:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Marked Text Example</title>
</head>
<body>
    <p>Remember to buy <mark>eggs and milk</mark> on your way home.</p>
</body>
</html>

Step 9: Monospaced Text and Preformatted Text

The <code> tag is used for inline code snippets, and the <pre> tag is used to display preformatted text which preserves both spaces and line breaks.

Example using <code>:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Code Snippet Example</title>
</head>
<body>
    <p>Use the following Python code to print a message:</p>
    <p><code>print("Hello, World!")</code></p>
</body>
</html>

Example using <pre>:

Top 10 Interview Questions & Answers on HTML Text Formatting Tags

1. What is the purpose of HTML Text Formatting Tags?

Answer: HTML Text Formatting Tags are used to format the appearance of text within a webpage. These tags can change the style of the text like making it bold, italic, underlined, or altering its color, size, and alignment. They help make the content more readable and visually appealing.

2. How do you make text bold in HTML?

Answer: To make text bold in HTML, you can use the <strong> or <b> tag. The <strong> tag is semantically correct, indicating that the text is of strong importance, while <b> is purely stylistic.

<p>This is <strong>bold text</strong>.</p>
<p>This is also <b>bold text</b>.</p>

3. How can you italicize text in HTML?

Answer: To italicize text, you can use the <em> or <i> tag. The <em> tag indicates that the text has emphasis, typically rendered as italic text by browsers, while <i> is used for stylistic presentation.

<p>This is <em>italicized text</em>.</p>
<p>This is also <i>italicized text</i>.</p>

4. How do you underline text in HTML?

Answer: To underline text, you can use the <u> tag. It's worth noting that <u> is used for non-textual annotation, which means it’s not intended to convey emphasis or strong importance as <strong> or <em> do.

<p>This is <u>underlined text</u>.</p>

5. How do you change the color of text in HTML?

Answer: To change the color of text, you can use the style attribute with the color property. You can specify the color using color names, hexadecimal values, or RGB values.

<p style="color: red;">This is red text.</p>
<p style="color: #00FF00;">This is green text (hex).</p>
<p style="color: rgb(0, 0, 255);">This is blue text (RGB).</p>

6. What are the ways to increase the size of text in HTML?

Answer: You can increase the size of text by using the style attribute with the font-size property. This property accepts values in different units like pixels (px), percentages (%), etc.

<p style="font-size: 24px;">This is large text (24px).</p>
<p style="font-size: 150%;">This is larger text (150%).</p>

7. How can you create a strikethrough effect in HTML?

Answer: To create a strikethrough effect, use the <s> or <del> tag. <s> stands for strikethrough, while <del> indicates deleted text, and is semantically correct when expressing editorial changes.

<p>This is <s>strikethrough text</s>.</p>
<p>This is also <del>deleted text</del>.</p>

8. How do you change the font family and style of text in HTML?

Answer: To change the font family and style, use the style attribute with font-family and font-style properties.

<p style="font-family: Arial, sans-serif;">This is text in Arial font.</p>
<p style="font-style: italic;">This is italic styled text.</p>

9. What is the difference between <pre> and <code> tags in HTML?

Answer: The <pre> tag is used for preformatted text and preserves both spaces and line breaks. The <code> tag is used to indicate text that should be displayed in a monospace font, typically used for code snippets.

<pre>This   text
    includes
      line breaks
        and   spaces.
</pre>

<p>Use <code>&lt;p&gt;</code> for paragraphs and &lt;br&gt; for line breaks.</p>

10. How do you highlight text in HTML?

Answer: To highlight text, you can use the <mark> tag, which applies a yellow background color to the text, typically to denote relevance or importance.

You May Like This Related .NET Topic

Login to post a comment.