HTML to XHTML in 10 StepsThere is very little difference in HTML and XHTML so if you are familiar with HTML then making the change to XHTML is very easy. There are a few syntax rules that you should obey and your documents should then have no problem being validated as XHTML.They are:
Add a Doctype DeclarationThe Doctype tag provides information ( Usually to html validator programs) about the HTML/XHTML on the web page and is optional in html but is mandatory for xhtml (xhtml). The Doctype is used by validation programs when checking your html for valid code (see validating web pages) and by browsers to render web pages.
The doctype should be the very first line of your document and comes even before the HTML Tag. It should be the only thing on that line and is case sensitive. There are three versions of XHTML and each one has an associated DTD (Document Type Definition)
The Doctype declaration for each is: "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd"> The Document Root Element Must be HTMLImmediately following the DTD, state the document root element as HTML. This is combined with the designation of the namespace. Designate the XHTML 1.0 namespaceThe root element (opening html tag) of the document must designate the XHTML 1.0 namespace. <html xmlns="http://www.w3.org/1999/xhtml" lang="en-US" xml:lang="en-US"> All Tags and Attribute Names are LowercaseIn HTML <html> and <HTML> where identical in XHTML they are different. In XHTML then <html> is correct and <HTML> is incorrect Every tag Needs an End TagIn HTML a line break was simply <BR> and didn't need a closing </BR> tag. in XHTML every tag needs a closing tag. See below:
Tags like the break tag which are empty tags as nothing goes between the start tag and end tag are usually more often written as: <br/> as a shortcut to <br></br> Elements Must be Properly Nested<p><b>This is wrong </p></b> In the example above the paragraph tag is closed before the bold tag. <p><b>This is correct</b></p> Attribute Values Must Always be Quoted<td rowspan="2"> is correct whereas <td rowspan=2> isn't. Add the "id" Attribute to Elements that have the Name AttributeTags such as the a, applet, form, frame, iframe, img, and map tags can also have a name attribute. e.g. <h1><a name="intro">Introduction</a></h1> The name attribute is being depreciated and is being replace by the id attribute. In XHTML this becomes: <h1><a id="intro">Introduction</a></h1> The syntax of the id attribute is similar to that of the name attribute and is written as id=”value” . However, for backward compatibility, it is best to use both attributes by adding the id attribute. So normally we will use this form: <h1><a name="intro" id="intro">Introduction</a></h1> Attribute MinimizationAttribute values must be written in full thus: <dl compact="compact"> is correct and <dl compact> is incorrect Encode AmpersandsIt is common to see ampersands as part of urls as shown in yellow highlight below add.my.yahoo.com/content?.intl=us&url=http://www.build-your-website.co.uk/ Although not correct in HTML it was generally ignored. In XHTML the amperstand must be encoded and would appear as & and not & . The example url above would be: add.my.yahoo.com/content?.intl=us&url=http://www.build-your-website.co.uk/ Specify Alt ImageRequired in HTML but largely ignored every image should have an alt attribute. This is valid: <img border="0" src="images/left.gif" width="180" height="80" alt="left-image" /> This is invalid: <img border="0" src="images/left.gif" width="180" height="80" > XHTML ExampleIn the example below I have highlighted a section in yellow this is necessary to add if you are going to validate the page.
This is the same but incorrect. I have highlighted the errors can you see what they are?
References and resources:
|
|||||
|
[Home page] [About us] [Privacy Policy] [Contact Me] |