|
So how do you sort out XHTML 1.0, 1.1, and 2.0? Will you have to learn how to create your own modules to be standards compliant? Eventually, perhaps, but not just yet. It will still be some years before browsers eliminate their “backward compatibility,” so you needn’t be in a rush to learn how to create XHTML modules or develop DTDs. However, the more standards compliant your documents are, the less maintenance they will require in the future. So there are definite advantages to learning how to adhere to the Strict DTD.
What should you do to make sure that your pages are ready for the future? The following principles will help you write well-formed and valid XHTML pages:
Always include closing tags. No exceptions. If an element takes an opening tag and a closing tag, always use both.
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 are a few instances in HTML where you didn’t need to add a value to an attribute. Usually this is because the attribute is self-explanatory. For example, using radio buttons, you could specify an option as preselected by adding the word “checked.” Checked was an attribute, but it didn’t take a value. Now you need, even in these cases, to include a value with the attribute, as in checked="checked".
Enclose all attribute values in quotation marks. In the past, you could get away with leaving these out, but not anymore. When you include an attribute value, put it in quotes, like this: attribute="value". No exceptions.
Write your code in lowercase. 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.
Use the id attribute instead of name. The name attribute is on the way out, being replaced by id. As much as possible, use id instead of name.
Make sure your tags are all correctly nested. No overlapping tags, period.
Check your documents to be sure they are well-formed. With HTML your documents should be well-formed (correctly written); with XHTML they must be well-formed.
Include a <!DOCTYPE> declaration in every document. Ideally, you should use the Strict DTD. That way your pages will have to conform to the stricter standards that are coming.
Tip | If you need some help remembering how to write a <!DOCTYPE> declaration, check out Chapter 7. |
Always Validate your HTML documents. Use the W3C’s validation service (or somebody else’s) to make sure your documents are not only well-formed but that they also conform to the XHTML Strict DTD. The corrections you receive from the validator are great tools to help you learn how to improve your code.
Use CSS for style. Learn to use Cascading Style Sheets. Browser support for CSS is growing, and soon the compatibility issues that have made them a mixed blessing will no longer be a problem. In fact, sooner or later you’ll have to use them anyway. Learn how to do it now.
Stop using presentational elements and attributes. Define your presentation with style sheets, not HTML.
Like it or not, the stricter standards of XHTML are the future of the Web. If you begin to write standards-compliant code now, future browser versions will have little or no trouble interpreting your code, even if you aren’t writing in XHTML 1.1 or 2.0.
Throughout this book you have learned how easy it is to create pages in XHTML. You have learned how to place the proper emphasis on structure in your markup and use CSS for style and design purposes. Most important, you have discovered that Web authoring isn’t some mystical process that can be undertaken only by “techies.” You now have the tools you need to create good, functional Web sites. However, keep in mind that if you don’t use these tools, you’ll probably lose (forget) them. XHTML markup is simple and intuitive, but if you are to become proficient as a Web author, you need to practice. So don’t close this book and put it on the shelf. Keep it handy—and start designing Web sites.
And don’t forget to have fun!
|