HTML Formatting

HTML Formatting

1. Formatting

HTML Formatting is a process of formatting text for a better look and feel. HTML provides us the ability to format text without using CSS. There are many formatting tags in HTML. These tags are used to make text bold, italicized, or underlined. There are almost 14 options available that how text appears in HTML and XHTML.

In HTML the formatting tags are divided into two categories:

  • Physical tag: These tags are used to provide a visual appearance to the text.
  • Logical tag: These tags are used to add some logical or semantic value to the text.

NOTE: Some physical and logical tags may give the same visual appearance, but they will be different in semantics.

Here, we are going to learn 14 HTML formatting tags. Following is the list of HTML formatting text

 

 

Element name Description
<b> This is a physical tag, which is used to bold the text written between it.
<strong> This is a logical tag, which tells the browser that the text is important.
<i> This is a physical tag that is used to make the text italic.
<em> This is a logical tag that is used to display content in italic.
<mark> This tag is used to highlight text.
<u> This tag is used to underline text written between it.
<tt> This tag is used to appear a text in teletype. (not supported in HTML5)
<strike> This tag is used to draw a strikethrough on a section of text. (Not supported in HTML5)
<sup> It displays the content slightly above the normal line.
<sub> It displays the content slightly below the normal line.
<del> This tag is used to display the deleted content.
<ins> This tag displays the content which is added
<big> This tag is used to increase the font size by one conventional unit.
<small> This tag is used to decrease the font size by one unit from base font size.

2. Bold Text

HTML and formatting elements

The HTML element is a physical tag which displays text in bold font, without any logical importance. If you write anything within ............ element, is shown in bold letters.

See this example:

<p> <b>Write Your First Paragraph in bold text.b>p> 

Output:

Write Your First Paragraph in bold text.

 

The HTML <strong> tag is a logical tag, which displays the content in bold font and informs the browser about its logical importance. If you write anything between <strong>???????. </strong>, is shown important text.

 

See this example:

 
  1. <p><strong>This is an important content</strong>, and this is normal content</p>  

Output:

This is an important content, and this is normal content

3. Example

 
  1. >  
  2. <html>  
  3. <head>  
  4.     <title>formatting elementstitle>  
  5. head>  
  6. <body>  
  7. <h1>Explanation of formatting elementh1>  
  8. <p><strong>This is an important contentstrong>, and this is normal contentp>  
  9. body>  
  10. html>  

 

Output

Explanation of formatting element

This is an important content, and this is normal content

4. Italic Text

HTML <i> and <em> formatting elements

The HTML <i> element is physical element, which display the enclosed content in italic font, without any added importance. If you write anything within <i>............</i> element, is shown in italic letters.

See this example:

 
  1. <p> <i>Write Your First Paragraph in italic text.</i></p>  

Test it Now

Output:

Write Your First Paragraph in italic text.

The HTML <em> tag is a logical element, which will display the enclosed content in italic font, with added semantics importance.

See this example:

 
  1. <p><em>This is an important content</em>, which displayed in italic font.</p>  

 

Output:

This is an important content, which displayed in italic font.

 
  1. <!DOCTYPE html>  
  2. <html>  
  3. <head>  
  4.     <title>formatting elements</title>  
  5. </head>  
  6. <body>  
  7. <h1>Explanation of italic formatting element</h1>  
  8. <p><em>This is an important content</em>, which displayed in italic font.</p>  
  9. </body>  
  10. </html>  

 

Output:

Explanation of italic formatting element

This is an important content, which displayed in italic font.

5. HTML Marked formatting

If you want to mark or highlight a text, you should write the content within <mark>.........</mark>.

See this example:

 
  1. <h2>  I want to put a <mark> Mark</mark> on your face</h2>   

 

Output:

I want to put a Mark on your face

6. Underlined Text

If you write anything within <u>.........</u> element, is shown in underlined text.

See this example:

 
  1. <p> <u>Write Your First Paragraph in underlined text.</u></p>  

 

Output:

Write Your First Paragraph in underlined text.

7. Strike Text

Anything written within <strike>.......................</strike> element is displayed with a strikethrough. It is a thin line that crosses the statement.

See this example:

 
  1. <p> <strike>Write Your First Paragraph with strikethrough</strike>.</p>  

 

Output:

Write Your First Paragraph with strikethrough.

8. Monospaced Font

If you want that each letter has the same width then you should write the content within <tt>.............</tt> element.

Note: We know that most of the fonts are known as variable-width fonts because different letters have different width. (for example: 'w' is wider than 'i'). Monospaced Font provides a similar space among every letter.

See this example:

 
  1. <p>Hello <tt>Write Your First Paragraph in monospaced font.</tt></p>     

 

Output:

Hello, Write Your First Paragraph in a monospaced font.

9. Superscript Text

If you put the content within <sup>..............</sup> element, is shown in superscript; means it is displayed half a character's height above the other characters.

See this example:

 
  1. <p>Hello, <sup>Write Your First Paragraph in superscript.</sup></p>     

 

Output:

Hello, Write Your First Paragraph in superscript.

10. Subscript Text

If you put the content within <sub>..............</sub> element, is shown in subscript; means it is displayed half a character's height below the other characters.

See this example:

 
  1. <p>Hello, <sub>Write Your First Paragraph in subscript.</sub></p>  

 

Output:

Hello, Write Your First Paragraph in subscript.

11. Deleted Text

Anything that puts within <del>..........</del> is displayed as deleted text.

See this example:

 
  1. <p>Hello <del>Delete your first paragraph.</del></p>  

 

Output:

Hello

12. Inserted Text

Anything that puts within .......... is displayed as inserted text.

See this example:

 
  1. <p> <del>Delete your first paragraph.del>.<ins>Write another paragraph.ins>p>  

 

Output:

Delete your first paragraph. Write another paragraph.

13. Larger Text

If you want to put your font size larger than the rest of the text then put the content within <big>.........</big>. It increases one font size larger than the previous one.

See this example:

 
  1. <p>Hello, <big>Write the paragraph in larger font.</big></p>  

 

Output:

Hello, Write the paragraph in a larger font.

14. Smaller Text

If you want to put your font size smaller than the rest of the text then put the content within <small>.........</small>tag. It reduces one font size than the previous one.

See this example:

 
  1. <p>Hello, <small>Write the paragraph a smaller font.</small></p>  

 

Output:

Hello, Write the paragraph in a smaller font.