HTML Characters Entities


Character entity

Some characters have special meaning in HTML, such as less than sign (<) that defines the beginning of an HTML tag. If we want the browser to display a smaller sign that (<), we must insert character entities in our HTML code.

Entities character has 3 components: an ampersand sign (&), entity name or a # followed by the number of entities and end with a semicolon (;).

To display a smaller sign in our HTML pages, then we must write: &lt; or <
The advantage of using a name than a number is that the name is easier to remember. The drawback is that not all browsers support the names of the new entity, however, almost all browsers support the entity name standard.
Note: The entity is case sensitive.

Spaces sequence

Character entities that may be most often you use is the space.
HTML will eliminate the spaces in your HTML text. If you write 10 spaces in your HTML code, the HTML will remove nine spaces. Now, to add space in your HTML document, use the character entities &nbsp;.

Some character entities that are often used:

  Space &nbsp;
< Less than &lt;
> More than &gt;
” Quotation marks &quot;
’ Single Quote &apos; (it doesn’t work on IE)
& Ampersand &amp;

Here's an example to clarify what is meant by character entities.
The case is very simple really. We're already know, if it uses the name HTML tag, right? One example is the tag <b> </ b> for bold letters.

Now imagine if one day you are asked to write a tutorial about HTML and the chance to write about HTML tags that serve to make letters bold. Say you want the following lines appear in your tutorial (note, you want to tag <b> and </ b> appear in that line.)

To thicken the letters as word of this thick, you need a tag <b> and </ b>

Well, think about it, how to write this simple line without character entities. Can not you? For example, you write like this:
To thicken the letters as word <b> bold </b> of this, you need a tag <b> and </b>

What happened? The browser will display the following sentence:
To thicken the letters as word of this thick, you need a tag and

What's the difference? Yes ... tag <b> and </ b> does not appear, instead, the word and will appear in bold.
To create a tag for <b> and </ b> to appear, you need character entities, so you must write the HTML code to be like this:
To thicken the letters as word <b> bold </b> of this, you need a tag &lt;b&gt; dan &lt;/b&gt;

Note, a < replaced with character entities &lt;, while the sign > I replaced with &gt;.
Other question is, How is the way of showing &gt; so it doesn’t appear >.
We can use &amp; in front of it to escape the & so that you can write like this &amp; &gt; (without space between &amp; and &gt;).

Hopefully this example can increase your understanding of what is meant by this character entities in HTML.

0 comments:

Post a Comment