Some Web Design Basics 1: XHTML
September 15th, 2007
In the interest of sharing information, this is the first in a series of “brain dump” posts regarding web design - specifically for folks who are starting a blog.
Much of what I’ve learned post-college has been from Jeffrey Zeldman, or the other site A List Apart. The basic idea behind their vision of “web standards” is to code with XHTML and CSS. A lot of really sloppy code was forgiven by the browsers of old, leading to pages that looked fine but were a pain to update (images cut into slices and laid out in tables comes to mind). Web politics aside, web standards are a good goal to strive for as they allow for the separation of content and design. The order also makes your code easier to read, understand, and parseable.
This might sound intimidating but I’ll break it into steps. I’ll start off with XHTML and how to code it. XHTML stands for EXtensible Markup Language and is a combination of XML and HTML. It’s pretty easy. Check out this article at A List Apart for the basics.
The basic rules are:
- XHTML elements must be properly nested
- XHTML elements must always be closed
- XHTML elements must be in lowercase
- XHTML elements must have one root element
And what this really means:
- All tags are lowercase - write <div> rather than <DIV>.
- All tags must be closed. If you have a <p>text you must have a corresponding </p> on the other end.
- Tags that don’t have a corresponding closing tag are closed within the tag: <br />, <img />, <hr />.
- Tags must be nested correctly: <p><em>text</em></p> rather than <p><em>text</p></em>.
- The root element bit means each page has a basic structure of: <html><head></head><body></body></html>
Some additional rules:
- All tag attributes must have quotes: <img width=”100″ height=”100″ />
- I’m not sure if this is required, but <b> and <i> are ideally replaced with <strong> and <em>.
- Now to make it clear that your document is XHTML the proper DOCTYPE is declared in the header. In general, I’ve been told to use XHTML 1.0 Transitional.
Once you have an XHTML document, it’s a great idea to run it through a validator over at W3C. Just enter the URL of your XHTML document and all the mistakes will be reported. That’s pretty much it. Really.
So how does all this apply to blogging? Well, WordPress right out of the box generates pages in XHTML. But here are some reasons why any blogger should know about XHTML:
- If you want to edit your blog’s theme or want to create your own.
- There is a “code view” available when writing posts in WordPress.
- A blog that doesn’t validate may have trouble being recognized by spiders that index your site for search engines.