Some characters have a special meaning in HTML. If we want the browser to actually display these characters we must insert character entities in place of the actual characters themselves.
Some of them are
I) Less than (<) – <
II) Greater than (>) – >
III) Ampersand (&) – &
IV) Apostrophe (‘) – '
V) Non breaking space –
VI) Quotation mark (“) – "
A character entity should start with ‘&’ and ends with ‘;’. Important note is that entities are case sensitive.
Non breaking space:
It is the most common character entity in HTML.
Normally HTML will truncate spaces in text.
For example, if you add 5 spaces in text, HTML will remove 4 of them.
So in order to add spaces in text, we have to use the character entity.
Example,
<p>Programming Tute</p>
Output: Programming Tute
<p>Programming Tute</p>
Output: Programming Tute
In order to avoid this you can use preformatted <pre> tag which preserves both spaces and line breaks. Mainly it is used for displaying computer codes.
For example,
<pre>
for i = 0 to 5
printPt
i++
</pre>
Output:
for i = 0 to 5
printPt
i++
You’ve hit the ball out the park! Inbidercle!