HTML Character Entities. Character Entities Some characters have a special meaning in HTML, like the...

6
HTML Character HTML Character Entities Entities

Transcript of HTML Character Entities. Character Entities Some characters have a special meaning in HTML, like the...

Page 1: HTML Character Entities. Character Entities Some characters have a special meaning in HTML, like the less than sign (

HTML Character Entities HTML Character Entities

Page 2: HTML Character Entities. Character Entities Some characters have a special meaning in HTML, like the less than sign (

Character Entities Character Entities

Some characters have a special meaning in Some characters have a special meaning in HTML, like the less than sign (<) that defines HTML, like the less than sign (<) that defines the start of an HTML tag. If we want the the start of an HTML tag. If we want the browser to actually display these characters we browser to actually display these characters we must insert character entities in the HTML must insert character entities in the HTML source.source.

Page 3: HTML Character Entities. Character Entities Some characters have a special meaning in HTML, like the less than sign (

Parts of a Character EntityParts of a Character Entity

A character entity has three parts: an A character entity has three parts: an ampersand (&), an entity name or a # and an ampersand (&), an entity name or a # and an entity number, and finally a semicolon (;). entity number, and finally a semicolon (;).

To display a less than sign in an HTML To display a less than sign in an HTML document we must write: document we must write: &lt;&lt; or or &#60;&#60;

Page 4: HTML Character Entities. Character Entities Some characters have a special meaning in HTML, like the less than sign (

Advantages vs. DisadvantagesAdvantages vs. Disadvantages

The advantage of using a name instead of a The advantage of using a name instead of a number is that a name is easier to remember. number is that a name is easier to remember. The disadvantage is that not all browsers The disadvantage is that not all browsers support the newest entity names, while the support the newest entity names, while the support for entity numbers is very good in support for entity numbers is very good in almost all browsers.almost all browsers.

NoteNote that the entities are case sensitive. that the entities are case sensitive.

Page 5: HTML Character Entities. Character Entities Some characters have a special meaning in HTML, like the less than sign (

Non-breaking Space Non-breaking Space

The most common character entity in HTML The most common character entity in HTML is the non-breaking space.is the non-breaking space.

Normally HTML will truncate spaces in your Normally HTML will truncate spaces in your text. If you write 10 spaces in your text HTML text. If you write 10 spaces in your text HTML will remove 9 of them. To add spaces to your will remove 9 of them. To add spaces to your text, use the &nbsp; character entity.text, use the &nbsp; character entity.

Page 6: HTML Character Entities. Character Entities Some characters have a special meaning in HTML, like the less than sign (

Common Character EntitiesCommon Character Entities

ResultResult DescriptionDescription Entity NameEntity Name Entity NumEntity Num

non-breaking spacenon-breaking space &npsp;&npsp; &#160;&#160;

<< less thanless than &lt;&lt; &#60;&#60;

>> greater thangreater than &gt;&gt; &#62;&#62;

&& ampersandampersand &amp;&amp; &#38;&#38;

““ quotation markquotation mark &quot;&quot; &#34;&#34;

‘ ‘ apostropheapostrophe && &#39;&#39;