What is HTML Text Formatting?
Text formats like bold, italics, underline, what are all the text formats possible in simple word document are also possible in html document. There is a big list of formatting tags in html. Anyhow we can learn and remember some basic formatting tags instead of confusing with the big list.
List of Basic Text Formatting Tags
| Tags | Description |
| <b> , <strong> | Used to make text as bold |
| <i> , <em> | To make italic text |
| <u> | To make text underlined |
| <sub> | To make subscripted text (Eg: O2, here 2 is subscripted) |
| <sup> | To make superscripted text (Eg: (a+b)2, here 2 is superscripted) |
| <code> | Defines computer code text |
| <address> | Defines an address element |
Where to use?
- The above formatting tags can be used to format only few words in a document. To format an entire paragraph or document, it is better to use style sheets rather than the above tags.
- It can be used where it is actually required. What I try to say is, if the text is necessarily want to be bold, then <b> can be used. Likewise, if some address is to be displayed, <address> tag can be used.
How to use?
- The formatting tags are paired tags, i.e., it has both start and end tag. So the text which is to be formatted to be given inside the tag. (E.g. <i>I want this text as italic</i>)
- More than one formatting tag can be also be used for the same texts. But make sure that the inner tag must end first before the outer tag ends.
I would like to explain this using an example
<b><i>This is a italic and bold text</i></b>
In this, I have used both bold and italic formatting tags for the same text. Here, <i> tag which lies inner to the <b> tag must to be closed first </i> and then the closing tag for </b> follows.
<b><i>This is an italic and bold text</b></i>
It’s a bad format though the browser renders it correctly. - Usage of two tags of same format would not show any big difference. (using both <b> and <strong> to the same text will not show any difference)
- Attributes like align, bgcolor, width and height cannot be declared. But class and id can be used within.
Example
<html>
<head>
<title>Example for text formatting tags</title>
<body>
<b>This is a bold text</b>
<strong>This is a strong text</strong>
<i>This is an italic text</i>
<em>This is an emphasized text</em>
<u>This is a underlined text</u>
<sub>This is a subscripted text</sub>
<sup>This is a superscripted text</sup>
<code>This is a computer code text</code>
<address>This is an address text</address>
</body>
</html>
<head>
<title>Example for text formatting tags</title>
<body>
<b>This is a bold text</b>
<strong>This is a strong text</strong>
<i>This is an italic text</i>
<em>This is an emphasized text</em>
<u>This is a underlined text</u>
<sub>This is a subscripted text</sub>
<sup>This is a superscripted text</sup>
<code>This is a computer code text</code>
<address>This is an address text</address>
</body>
</html>
Next lesson deals with the html attributes. List of html attributes, where and how to use html attributes can be seen in detail.
Advertisement