Home arrow HTML arrow Page 2 - An Introduction to XHTML
HTML

An Introduction to XHTML


XHTML reformulates the existing HTML technology to be an application of XML. It is already used for mobile phone and PDA Internet sites, and expected to gain widespread use as XML becomes more popular. Dan Wellman explains the differences between XHTML and HTML 4, and shows how easy it is to make the switch.

Author Info:
By: Dan Wellman
Rating: 4 stars4 stars4 stars4 stars4 stars / 42
December 01, 2004
TABLE OF CONTENTS:
  1. · An Introduction to XHTML
  2. · No lazy programming allowed
  3. · Conform to the rules
  4. · The table structure
  5. · Namespace awareness

print this article
SEARCH DEVARTICLES

An Introduction to XHTML - No lazy programming allowed
(Page 2 of 5 )

One of the most striking differences between HTML and XHTML is the conformance to pre-defined rules. HTML allows Web programmers to be fairly lazy in the way they create their mark-up; tags may be written in upper or lowercase or even a combination of the two. Tags that are considered deprecated, or no longer relevant for use, may also be used, as can browser-specific tags, like the <layer> tag in Netscape. It is very easy to get into bad coding habits when working with HTML. For example, the following code is perfectly acceptable in HTML:

<p>Paragraph 1

XHTML is a much stricter language. All element tags must be written in lowercase, and any empty element tags must be closed off properly.  An empty element is defined as an element that does not contain any actual text that is displayed by the browser. The <img> element is an excellent example of this. The following code snippet tells the browser to display an image called logo.gif contained in the same directory as the Web page:

<img src="logo.gif">

XHTML insists that any empty elements be closed in the correct manner with a space and a forward slash at the end:

<img src="logo.gif />

The space before the forward slash is not strictly necessary when using the latest browser versions, but for maximum compatibility with older browsers, the space should always be included. When using images in XHTML, remember that the alt attribute is a mandatory requirement, without which, your document will not validate.

Opening and closing, or paired elements do contain text that the browser displays, like the <p> or paragraph element:

<p>This text will appear in the main browser window</p>

XHTML demands that all opening and closing elements are paired correctly. I hope this example easily distinguishes the difference between empty and paired elements. It also specifies that all non-empty elements have both an opening and a closing tag.

Another difference is that all attribute values are enclosed within quotes in XHTML. In HTML quotes are not always used for attribute values, which again allows the programmer to slip into bad habits.  Additionally, all attributes must have values; in the case of attributes that by default do not have values, you need to set the value equal to the attribute itself, the noshade attribute for example, must be set in the following format:

noshade="noshade"


blog comments powered by Disqus
HTML ARTICLES

- Does HTML5 Need a Main Element?
- Revisiting the HTML5 vs. Native Debate
- HTML5: Not for Phone Apps?
- HTML5 or Native?
- Job Hunting? Freelancer.com Lists This Quart...
- HTML5 in the News
- Report: HTML5 Mobile Performance Lags
- The Top HTML5 Audio Players
- Top HTML5 Video Tutorials
- HTML5: Reasons to Learn and Use It
- More of the Top Tutorials for HTML5 Forms
- MobileAppWizard Releases HTML5 App Builder
- HTML5 Boilerplate: Working with jQuery and M...
- HTML5 Boilerplate Introduction
- New API Platform for HTML5

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 

Developer Shed Affiliates

 




© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials