Entities

There will be times when you want to include a character in your web page that either has a special meaning in HTML or which does not have a key available on the keyboard to allow you to enter it. When these situations occur you can use one of the predefined entities within XHTML to specify the character that is to be displayed on the page.

Let's srart by considering those characters that have a special meaning to XHTML and which therefore get interpreted as parts of XHTML commands if you enter them directly into your web page source. There are three characters that fall into this group - the less than and greater than symbols (which are interpreted as the start and end of an XHTML tag respectively) and the ampersand (which is interpreted as the start of an entity reference. To be able to enter these three characters into the actual content of our web page we need to specify the entity equivalents instead of the characters themselves.

All entities, not just these three start with an ampersand followed by the name of the entity and end with a semi-colon. To put a semi-colon into your page content does not need to use an entity substitution because unlike the greater than symbol which can potentially appear within an XHTML tag and not just as the terminator for it, semi-colons that terminate entities are easily found since they follow an ampersand and entity name without any intervening spaces.

The second use for entities is to display characters in the page which are a known part of the character set that the page is using but which are not found on the keyboard. Some examples of such usage include copyright © ©, pounds £ £, and accented characters eg. á á.

It is also possible to specify ascii codes in attributes by using the format ϧ (where 999 is the hex value of the ascii code) but not all codes are correctly recognised by all browsers and so I recommend that you avoid this usage of entities.

 

This article written by Stephen Chapman, Felgall Pty Ltd.

go to top

FaceBook Follow
Twitter Follow
Donate