HTML Text Formatting

by | Apr 10, 2023 | HTML

Table of Contents

What is HTML Text Formatting?

HTML text formatting refers to the process of changing the appearance of text on a web page using HTML tags and attributes. HTML provides a variety of tags for formatting text, including bold, italic, underline, deleted text, subscript, superscript, etc.

These tags can be used individually or in combination to create various text formatting styles. For example, to make text both bold and italic, you can use the <b> and <i> tags together like this: <b><i>text</i></b>. HTML text formatting can be used to make content more visually appealing and easier to read.

HTML <b> and <strong> tags

HTML <b> tag is used to define bold text without any extra importance in HTML Text Formatting.

<!DOCTYPE html>
<html>
  <body>

    <p>This text is normal text.</p>

    <p><b>This is a bold text.</b></p>

  </body>
</html>

HTML <strong> tag defines bold text with extra importance. This is a very important tag in HTML Text Formatting.

<!DOCTYPE html>
<html>
<body>

<p>This text is normal text.</p>

<p><strong>This text is bold with extra importance.</strong></p>

</body>
</html>

HTML <i> and <em> Tags

HTML <i> tag defines italic text without extra importance like <b> tag.

<!DOCTYPE html>
<html>
  <body>

    <p>This text is normal text.</p>

    <p><i>This is an italic text.</i></p>

  </body>
</html>

HTML <em> tag defines italic text with extra importance like the <strong> tag. This is an important tag in HTML Text Formatting.

<!DOCTYPE html>
<html>
  <body>

    <p>This text is normal text.</p>

    <p><em>This is an italic text with extra importance.</em></p>

  </body>
</html>

HTML <u> tag

HTML <u> tag defines underlined text.

<!DOCTYPE html>
<html>
  <body>

    <p>This text is normal text.</p>

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

  </body>
</html>

HTML <del> tag

HTML <del> tag defines a deleted text and puts a line through the text.

<!DOCTYPE html>
<html>
  <body>

    <p>This text is normal text.</p>

    <p>The price of the book is <del>$30</del> $25</p>

  </body>
</html>

HTML <sub> and <sup> Tags

The <sub> tag is particularly useful for displaying chemical formulas, footnotes, or mathematical expressions that require a smaller font size or a lowered position on the page.

Displaying the chemical formula for water (H2O) using HTML Text Formatting ( <sub> tag ):

<!DOCTYPE html>
<html>
  <body>

    <p>Here is the chemical formula for water:</p>

    <p> H<sub>2</sub>O </p>

  </body>
</html>

The <sup> tag is particularly useful for displaying exponents, footnotes, or mathematical expressions that require a smaller font size or a raised position on the page.

Here is an example of how to use the <sup> tag to display a mathematical expression:

<!DOCTYPE html>
<html>
  <body>

    <p>Here is a mathematical expression:</p>

    <p> x<sup>2</sup> + y<sup>2</sup> </p>

  </body>
</html>

HTML <mark> tag

The HTML <mark> tag is used to highlight or mark a specific section of text within an HTML document. It is often used to draw attention to a specific word or phrase and is commonly used in search engine results or for highlighting keywords in online articles.

The <mark> tag does not have any required attributes and can be used within most HTML elements, such as paragraphs, <span>, headings, etc. Here’s an example of how to use the <mark> tag:

<!DOCTYPE html>
<html>
  <body>

    <p>My favourite color is <mark>blue</mark>.</p>

  </body>
</html>

When rendered in a web browser, the word “blue” will be highlighted with a yellow background, indicating that it is a marked section of text. The appearance of the highlighted text can be customized using CSS to match the design of the website.

HTML Text Formatting Cheatsheet

  1. <b> (bold): Renders text in bold font style.
  2. <strong> (bold and important): Renders text in bold and gives an importance
  3. <i> (italic): Renders text in italic font style.
  4. <em> (emphasized): Renders emphasized text
  5. <u> (underline): Underlines text.
  6. <del> (deleted): Puts a line through the text and defines the text as a deleted text.
  7. <sub> (subscript): Renders text as a subscript, which appears smaller and below the baseline.
  8. <sup> (superscript): Renders text as a superscript, which appears smaller and above the baseline.
  9. <mark> (mark): Used to highlight and visually distinguish text within a document or webpage.

HTML Element Reference: W3Schools

Calendar

December 2024
M T W T F S S
 1
2345678
9101112131415
16171819202122
23242526272829
3031