Martin Francis

Blog of Web Designer Martin Francis

Jun 10


2 screen shots of web design pages

Discuss the differences between HTML and XHTML. Provide code examples to illustrate these differences.

HTML has gone through many versions from the original 1.0. Including in HTML 3.0 with it’s presentational elements brought in by different browsers so a web page can look great in the web designers favourite browser but rubbish in others.
The final version HTML 4.01 and in strict form has a lot in common with the XHMTL 1.0 Strict with it’s separation of structure from presentation using CSS.

Standards compliant web browsers will even render XHTML 1.0 Strict as HTML 4.01 Strict.

XHTML is actually a version of XML with more strict rules than HTML which is a version of SGML (standardised general markup language).
The Most Important Differences:
• XHTML elements must be properly nested
• XHTML elements must always be closed
• XHTML elements must be in lowercase
• XHTML documents must have one root element

Coding examples include self closing of empty elements tags such as
<img src=“picture.jpg”>

must now become

<br />
<img src=“picture.jpg” />
<link />
<meta />

So why use XHTML over HTML?

XHTML’s strict syntax allows aural readers and other browsers for the visually impaired to more easily consume web content.
XHTML can be extended to include new markup.
XHTML is able to be read by mobile devices.

To take a page from HTML to XHTML:–

Change the DOC type,
Add the xmls, xml:lang, and lang attribute to the opening HTML tag.
Change the ending of empty elements from this > to this />
Change HTML special characters from to their entities for example & to &amp; and – to &ndash;.

Posted by: martin Last updated on:2010-08-05 11:41:38
Tag:- xhtml