HTML Character Entities

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 (<) – &lt;

II)           Greater than (>) – &gt;

III)         Ampersand (&) – &amp;

IV)          Apostrophe (‘) – &apos;

V)           Non breaking space – &nbsp;

VI)          Quotation mark (“) – &quot;

 

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 &nbsp; character entity.

 

Example,

 

<p>Programming                           Tute</p>

 

Output: Programming Tute

 

<p>Programming &nbsp;&nbsp;&nbsp;&nbsp; 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++

Posted on July 27, 2014 in HTML

Share the Story

Response (1)

  1. Corina
    February 18, 2016 at 1:41 am · Reply

    You’ve hit the ball out the park! Inbidercle!

Leave a reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Back to Top