As you have seen thus far, Cascading Style Sheets go a long way toward addressing the problems caused by HTML’s limitations. However, some problems remain that CSS cannot deal with. The explosive growth and development of the World Wide Web has stretched HTML far beyond its capacity. After all, HTML was not created with the intent of enabling designers to craft attractive Web pages, nor was it developed to address the many new technologies that are coming on the scene. People can now access the Internet in many ways other than through Web browsers and telephone lines. Now, you can use a PDA or even access the Internet through your cell phone. This has created a need for a language that is more flexible than HTML, a language that can be extended and developed as technology changes. That language is XML, the Extensible Markup Language.
HTML is a “fixed” language. That is, you can’t modify it to suit your own purposes or needs. HTML has a set structure that you must follow if you want your pages to work. With HTML you have a certain collection of elements and attributes with which to work, and you cannot customize it by adding your own elements. XML, on the other hand, is an extensible language. With XML, you can create your own elements, tags, attributes, and values. That’s where the term “extensible” comes in. You extend XML by creating other markup languages with it.
XML is not just another markup language; it’s a meta language. In programming terminology, the word “meta” refers to description. Well, a meta language is a language that can describe other languages. For example, SGML (Standard Generalized Markup Language) is the meta language that was used to create HTML. If you go to the W3C’s site and read the current specification for HTML, you can actually read the SGML code (known as a Document Type Description or DTD) that was used to define and describe HTML. XML is also a “child” language of SGML, but it has one important distinction from its sibling, HTML. XML is extensible. In other words, it was designed to enable its users to create their own customized markup languages. Does that mean you will have to use XML to create your own markup languages for your Web pages in the future? No, that’s where XHTML comes in.
The current recommendation (standard) of the W3C for Web pages is no longer HTML, but XHTML, the Extensible Hypertext Markup Language. XHTML is simply HTML rewritten in XML. You still use the familiar HTML elements, attributes, and values, but in reality you are working with a much more flexible and powerful language: XML. Thus, with XHTML you have a combination of HTML’s familiarity and ease of use with XML’s flexibility.
So, how do you write XHTML pages? For the most part, you have been learning how to do it throughout these three chapters. However, in case you’re still fuzzy on the subject, keep the following principles in mind. There are some more advanced rules for writing XHTML pages, which we’ll cover later, but for the present these are all you need:
Always include closing tags. No exceptions. If an element takes an opening tag and a closing tag, always use both. Gone are the good old days of HTML when you could just put a <p> tag at the beginning of every new paragraph and ignore the </p>.
Empty elements must always have a closing slash. If you use an empty element (an element that does not enclose content), always make sure that you include a space and a closing slash in the tag, like this: <img />.
Always include a value with an attribute. There were some instances in HTML where it wasn’t necessary to include a value with an attribute. Usually this was because the attribute was self-explanatory. For example, when creating a form in HTML, you could sometimes specify an option as preselected by adding the word “checked” inside the tag. Checked was an attribute, but it didn’t require a value. Now, even in these cases you must include a value, as in: checked="checked". Yes, it’s redundant, but that’s the way it goes sometimes.
Enclose all attribute values in quotation marks. In the past, you could get away with leaving the quotation marks out, but not anymore. When you enter a value in an attribute, put it in quotes, like this: attribute="value". No exceptions.
Write your code in lowercase. You will often find HTML pages that are a mixture of upper and lowercase. Since HTML was not case sensitive, it didn’t really matter. However, XHTML is case sensitive. By getting in the habit of writing all your code lowercase, you’ll be a long way down the road toward compatibility with the new standard.
Make sure your tags are all correctly nested. No overlapping tags, period. Sometimes HTML will let you get away with this. XHTML is not so forgiving. Double-check your markup to eliminate any overlapping elements.
If you make these practices part of your regular coding routine, you will have little or no trouble making the transition to the future of the Web, XHTML.