XHTML Syntax
Some More XHTML Syntax Rules
- Attribute names must be in lower case
- Attribute values must be quoted
- Attribute minimization is forbidden
- The id attribute replaces the name attribute
- The XHTML DTD defines mandatory elements
Attribute Names Must Be In Lower Case
This is wrong:
This is correct:
Attribute Values Must Be Quoted
This is wrong:
This is correct:
Attribute Minimization Is Forbidden
This is wrong:
<input checked>
<input readonly>
<input disabled>
<option selected>
<frame noresize> |
This is correct:
<input checked="checked" />
<input readonly="readonly" />
<input disabled="disabled" />
<option selected="selected" />
<frame noresize="noresize" /> |
Here is a list of the minimized attributes in HTML and how they should be written in XHTML:
| HTML |
XHTML |
| compact |
compact="compact"
|
| checked |
checked="checked"
|
| declare |
declare="declare"
|
| readonly |
readonly="readonly"
|
| disabled |
disabled="disabled"
|
| selected |
selected="selected"
|
| defer |
defer="defer"
|
| ismap |
ismap="ismap"
|
| nohref |
nohref="nohref"
|
| noshade |
noshade="noshade"
|
| nowrap |
nowrap="nowrap"
|
| multiple |
multiple="multiple"
|
| noresize |
noresize="noresize"
|
The id Attribute Replaces The name Attribute
HTML 4.01 defines a name attribute for the elements applet, frame, iframe,
and img. In XHTML the name attribute is deprecated. Use id instead.
This is wrong:
| <img src="picture.gif" name="pic1" /> |
This is correct:
| <img src="picture.gif" id="pic1" /> |
Note: To interoperate with older browsers for a while, you should use both name and id, with identical attribute values, like this:
| <img src="picture.gif" id="pic1" name="pic1" /> |
IMPORTANT Compatibility Note:
To make your XHTML compatible with today's browsers, you should add an extra space before the "/" symbol.
The Lang Attribute
The lang attribute applies to almost every XHTML element. It specifies the language of the content within an element.
If you use the lang attribute in an element, you must also add the xml:lang attribute, like this:
| <div lang="no" xml:lang="no">Heia Norge!</div> |
Mandatory XHTML Elements
All XHTML documents must have a DOCTYPE declaration. The html, head, title, and body elements must be present.
This is an XHTML document with a minimum of required tags:
<!DOCTYPE Doctype goes here>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Title goes here</title>
</head>
<body>
</body>
</html> |
Note: The DOCTYPE declaration is not a part of the XHTML document itself. It is not an XHTML element. You will learn more about the XHTML
DOCTYPE in the next chapter.
Note: The xmlns attribute in <html>, specifies the xml namespace for
a document, and is required in XHTML documents. However, the HTML validator at
w3.org does not complain when the xmlns attribute is missing. This is because
the namespace "xmlns=http://www.w3.org/1999/xhtml" is default, and will be added
to the <html> tag even if you do not include it.
Reliable, Affordable, Feature-Rich Web Hosting!
Take the uncertainty out of Web hosting and let
GoDaddy.com put service, performance and value back in. No matter which
hosting type or plan you choose, your site receives 24/7
maintenance and protection in our world-class data center. Plus,
you get the expert, friendly service you deserve, from the
world's largest hostname provider.
With three plans to choose from and
prices starting at just $4.99 per month, GoDaddy.com is sure to have a plan that's
right-sized and right-priced just for you!
All plans feature FREE 24x7 setup, FREE 24x7 monitoring, best-
of-breed routers, firewalls and servers, 24x7 onsite physical security
and access to our exclusive Go Daddy Hosting Connection, THE place
to install over 30 FREE applications. Virtual Dedicated and Dedicated
Server plans also available.
Visit GoDaddy.com today.
Virtual Dedicated, Dedicated Server and unlimited plans also available.
Save 20% on 12 months or more of shared web hosting - Enter code w3s20off at checkout
|