Previous

Text formatting in HTML

Next

Text formatting in HTML allows you to modify the appearance of text within your web page content. There are several HTML tags and attributes specifically designed for text formatting purposes. Let's explore each of them in detail with examples and their corresponding output.

 

1. Bold Text (<strong>)

The <strong> tag is used to indicate that the enclosed text should be rendered in a bold font. It conveys semantic importance, suggesting that the text is of strong importance or emphasis.

Example:

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

Output:
This is bold text.

2. Italic Text (<em>)

The <em> tag is used to indicate emphasis, rendering the enclosed text in italics by default. Italicized text typically indicates a change in voice or mood.

Example:

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

Output:
This is italicized text.

3. Underlined Text (<u>)

The <u> tag is used to underline text. It visually distinguishes the enclosed text by placing a horizontal line underneath it.

Example:

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

Output:
This is <u>underlined text</u>.

4. Strikethrough Text (<s>)

The <s> tag is used to render text with a strikethrough effect, indicating that the text is no longer accurate or relevant.

Example:

<p>This is <s>strikethrough text</s>.</p>

Output:
This is <s>strikethrough text</s>.

5. Subscript Text (<sub>)

The <sub> tag is used to render text as subscript, typically used for chemical formulas, mathematical expressions, or footnotes.

Example:

<p>This is H<sub>2</sub>O.</p>

Output:
This is H<sub>2</sub>O.

6. Superscript Text (<sup>)

The <sup> tag is used to render text as superscript, often used for mathematical exponents, ordinal numbers, or citations.

Example:

<p>The area of a circle is π<sup>r</sup><sup>2</sup>.</p>

Output:
The area of a circle is π<sup>r</sup><sup>2</sup>.

7. Marked or Highlighted Text (<mark>)

The <mark> tag is used to highlight or mark portions of text, indicating relevance or highlighting specific terms or sections.

Example:

<p>This paragraph contains <mark>important information</mark>.</p>

Output:
This paragraph contains <mark>important information</mark>.

8. Small Text (<small>)

The <small> tag is used to render text in a smaller font size, typically used for disclaimers, legal notices, or copyright information.

Example:

<p>This text is <small>smaller in size</small>.</p>

Output:
This text is <small>smaller in size</small>.