Article

XHTML Web Design for Beginners - Part 2

Page: 1 2 3 4 5 6 7 8 9 10 11 Next

Part 2
Advanced XHTML Building Blocks

Before we look at any more elements, there are a few basic building blocks of XHTML that we need to cover, so that you can grasp the topics we'll examine next.

Hopefully, you now have an understanding of elements, start tags, end tags, the basic structure of an XHTML document, and the text elements we looked at in the previous section.

In this section, we'll be looking at the following topics:

  • Character References and Entity References
  • White Space
  • Comments

Character References and Entity References

Character references aren't as intimidating as they sound (no need to sweat!). Let's find out why they exist, then we'll look at how to code and use them.

Take a look at your keyboard. Can you type a copyright symbol, ©, or an inverted exclamation mark, ¡ ? Unless you're using a pretty strange keyboard, the answer is 'no.'

Imagine you're a Web browser (User Agent) reading a Web page file and you come across a left angle bracket <. How do you know if it's the start of a tag, or an angle bracket used in the content of the document? You don't.

So, what's the solution to these two problems? Entity references and character references!

Entity references and character references are extremely similar in XHTML, and people often confuse the two names. Basically, both tell the Web browser (or User Agent) that it should insert a certain character in their place.

If you don't know what the word "character" specifically refers to, it's a catch-all word for a letter, number, punctuation mark, etc. A is one character, AB is two characters, N!P 3 is five characters (four? you forgot to count the space!) …You get the idea.

A character reference or entity reference represents one character in XHTML. Entity references can represent more than one character in SGML or XML, but that's another story -- you don't need to worry about it right now.

The difference between a character reference and an entity reference is this:

  • Character references use numbers
  • Entity references use names

Let's look at the copyright symbol we saw above. To insert a copyright symbol into your document, you'd use either of the following:

&copy;

Try the &copy; entity reference.

&#169;

Try the &#169; character reference.

If you try the examples above (and your Web browser isn't broken) you'll see that a copyright symbol displays in both cases. As I said before, the entity reference uses names (in this case, "copy"), while the character reference uses numbers (here, "169"). Observant readers will notice that the character reference also includes a sharp (or hash, or pound) symbol ("#"). Let's take a closer look.

If you liked this article, share the love:
Print-Friendly Version Suggest an Article

Sponsored Links