Writing Code
XHTML
Declare a Document Type
Per HTML and XHTML standards, a DOCTYPE (short for “document type declaration”) informs the validator which version of (X)HTML you’re using, and must appear at the very top of every web page. Valid HTML/XHTML is important for creating documents that are accessible. DOCTYPE declarations are the key to compliant web pages. Your page won't validate to W3C standards if the proper doctype is not declared.
- XHTML 1.0 Transitional is closest to HTML 4. It forgives presentational markup and deprecated elements and attributes.
- XHTML 1.0 Strict
- The DOCTYPE declaration must be typed into the top of every XHTML document before any other code or markup. It precedes the <html> and <head> elements.
- Example:
<!DOCTYPE html PUBLIC "=//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
Some Basic XHTML Rules
- Include proper DOCTYPE
- Element and attribute names must be in lower case
- Attribute values must be quoted
- Attribute minimization is forbidden
- Close all tags
- Close empty tags with a space and a slash – example <hr />, <img />, <br />
- The id attribute replaces the name attribute
