<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Gabriel Jones &#187; xhtml</title>
	<atom:link href="http://gabrieljones.com/category/xhtml/feed/" rel="self" type="application/rss+xml" />
	<link>http://gabrieljones.com</link>
	<description>Web Developer Weblog</description>
	<lastBuildDate>Fri, 29 Jul 2011 13:27:49 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Writing Good XHTML</title>
		<link>http://gabrieljones.com/the-perfect-xhtml/</link>
		<comments>http://gabrieljones.com/the-perfect-xhtml/#comments</comments>
		<pubDate>Wed, 23 May 2007 02:29:45 +0000</pubDate>
		<dc:creator>Gabriel</dc:creator>
				<category><![CDATA[html]]></category>
		<category><![CDATA[xhtml]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://gabrieljones.com/?p=14</guid>
		<description><![CDATA[A recent project has forced me to take a closer look at how valid HTML code really is.  My task was to improve performance, validate, and standardize the code.  In later articles I will discuss my research, development, and conclusions to improving the company&#8217;s site performance.  But for now, I am going [...]]]></description>
			<content:encoded><![CDATA[<p>A recent project has forced me to take a closer look at how valid HTML code really is.  My task was to improve performance, validate, and standardize the code.  In later articles I will discuss my research, development, and conclusions to improving the company&#8217;s site performance.  But for now, I am going to focus on how to write the perfect XHTML document.</p>
<p>XHTML is a set of document types that reproduce and extend HTML 4, are XML based, and are designed to work with both XML-based and HTML-based user agents.  That is, XHTML must conform not only to HTML standards, but conform strictly to XML standards as well.</p>
<p>The differences in HTML and XHTML are strict conformity.  A best practice for both standard HTML and XHTML is to conform to one of three DTD&#8217;s, Strict, Transitional, or Frameset, and to declare the DOCTYPE. Which can be written as follows:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">&amp;lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&amp;gt;</pre></td></tr></table></div>

<p>The root element of the document <strong>must</strong> be <em>html</em>, and <strong>must</strong> contain the XML namespace (<em>xmlns</em>) declaration.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">&amp;lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot; xml:lang=&quot;en&quot; lang=&quot;en&quot;&amp;gt;</pre></td></tr></table></div>

<p>According to W3C, its a good idea to have an xml declaration, but it is not required.  I personally leave xml declarations for xml only documents.</p>
<p>As said earlier, the major difference between HTML and XHTML is strict conformity, the documents <strong>must</strong> be well-formed. Elements must be properly nested.</p>
<p><span style="color: green">Correctly</span> nested element:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">&amp;lt;p&amp;gt;Lorem ipsum dolor sit amet, &amp;lt;i&amp;gt;consectetuer&amp;lt;/i&amp;gt; adipiscing elit.&amp;lt;/p&amp;gt;</pre></td></tr></table></div>

<p><span style="color: red">Incorrecly</span> nested element:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">&amp;lt;p&amp;gt;Lorem ipsum dolor sit amet, &amp;lt;i&amp;gt;consectetuer adipiscing elit.&amp;lt;/p&amp;gt;&amp;lt;/i&amp;gt;</pre></td></tr></table></div>

<p>Because XHTML is interpreted as XML documents, all tags must be lowercase, because XML is case-sensitive. This also pertains to tag attributes as well.  It is best practice to create all markup language in lowercase whenever possible.</p>
<p><span style="color: green">Correct</span></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">&amp;lt;strong&amp;gt;Hello World&amp;lt;/strong&amp;gt;</pre></td></tr></table></div>

<p><span style="color: red">Incorrect</span></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">&amp;lt;STRONG&amp;gt;Hello World&amp;lt;/STRONG&amp;gt;</pre></td></tr></table></div>

<p>XML does not allow end tags to be omitted, thus, all non-empty tags <strong>must</strong> be closed.  If an element is empty, it must be properly closed. The only tag that does not close is the DOCTYPE declaration as it is not part of the XHTML document.</p>
<p><span style="color: green">Good</span></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">&amp;lt;br /&amp;gt;</pre></td></tr></table></div>

<p><span style="color: red">Bad</span></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">&amp;lt;br&amp;gt;</pre></td></tr></table></div>

<p>All attribute values <strong>must</strong> be contained in quotes and minimized attributes are unsupported.</p>
<p><span style="color: green">Good</span></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">&amp;lt;input checked=&quot;checked&quot; type=&quot;checkbox&quot; /&amp;gt;</pre></td></tr></table></div>

<p><span style="color: red">Bad</span></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">&amp;lt;input checked type=checkbox /&amp;gt;</pre></td></tr></table></div>

<p>It is best practice to wrap your script content in CDATA elements to avoid parsing of HTML markup such as <span style="color: green">&lt;</span> and <span style="color: green">&amp;</span>.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">&amp;lt;script type=&quot;text/javascript&quot;&amp;gt;
&amp;lt; ![CDATA[
// script content here
]]&amp;gt;
&amp;lt;/script&amp;gt;</pre></td></tr></table></div>

<p>The <strong>id</strong> attribute is replacing the <strong>name</strong> attribute in future versions of XHTML.  Currently it is best practice to have both named attributes of the same value until future releases of XHTML where then it will be best practice to remove the <strong>name</strong> attribute all together.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">&amp;lt;form id=&quot;commentform&quot; name=&quot;commentform&quot; method=&quot;post&quot;&amp;gt;&amp;lt;/form&amp;gt;</pre></td></tr></table></div>

<p>Today it is standard to have alt tags for images, objects, and buttons. However, not all browsers support the alt attribute, so title is used instead.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">&amp;lt;img src='image.jpg' title='My Image' /&amp;gt;</pre></td></tr></table></div>

<p>As long as you follow these standards throughout your entire document you will have a valid XHTML document.</p>
]]></content:encoded>
			<wfw:commentRss>http://gabrieljones.com/the-perfect-xhtml/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

