Address: http://www.w3schools.com/xhtml/xhtml_syntax.asp
Translation: Fan weixiao
Writing XHTML demands a clean HTML syntax.
We need to use clean HTML syntax to write XHTML pages.
Some more XHTML syntax rules:
More XHTML syntax rules:
Attribute names must be in lower case
Attribute names must be in lower case
This is wrong:
ErrorCode:
& Lt; table width = "100%" & gt;
This is correct:
Correct code:
& Lt; table width = "100%" & gt;
Attribute values must be quoted
The attribute value must be enclosed in quotation marks.
This is wrong:
Error code:
<Table width = 100%>
This is correct:
Correct code:
& Lt; table width = "100%" & gt;
Attribute minimization is forbidden
Attribute abbreviations are forbidden.
This is wrong:
<DL compact>
<Input checked>
<Input readonly>
<Input disabled>
<Option selected>
<Frame noresize>
This is correct:
<DL compact = "Compact">
<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 shoshould be written in XHTML:
simplified attributes in HTML and the list of the attributes to be written in XHTML:
html xhtml
compact =" Compact "
checked =" checked "
declare =" declare "
readonly =" readonly "
disabled Disabled =" disabled "
selected =" selected "
defer =" Defer "
ismap =" ismap "
nohref = "nohref"
noshade = "noshade"
nowrap = "nowrap"
multiple = "multiple"
noresize = "noresize"
The ID attribute replaces the name attribute
Use the ID attribute to replace the name attribute
HTML 4.01 defines a name attribute for the elements a, applet, frame, IFRAME, IMG, and map. In XHTML the name attribute is deprecated. Use Id instead.
A name attribute is defined in a, applet, frame, IFRAME, IMG, map, and HTML 4.01, which is not supported in XHTML. ID is used instead of name.
This is wrong:
This is correct:
Note: to interoperate with older browsers for a while, you should use both name and ID, with identical attribute values, like this:
Note: For browsers with lower versions, you should use the name and ID attributes at the same time, and their values should be the same, just like this:
The lang attribute
Lang attributes
The lang attribute applies to almost every XHTML element. It specifies the language of the content within an element.
The lang attribute can be applied to almost all XHTML elements. It specifies the language set of the element content.
If you use the lang attribute in an element, you must add the XML: lang attribute, like this:
If you apply the lang attribute to an element, you must add the XML: lang attribute, as shown in the following figure:
<Div lang = "no" XML: lang = "no"> heia Norge! </Div>
Mandatory XHTML Elements
Mandatory XHTML Elements
All XHTML documents must have a doctype declaration. The HTML, head and body elements must be present, and the title must be present inside the head element.
All XHTML documents must have a doctype. The HTML, Head, and body elements must appear, and the title must appear in the head.
This is a minimum XHTML document template:
This is the smallest XHTML document template.
<! Doctype goes here>
<HTML xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Title> title goes here </title>
</Head> <body>
Body text goes here
</Body> Note: The doctype Declaration is not a part of the XHTML document itself. It is not an XHTML element, and it shoshould not have a closing tag.
Note: The doctype declaration is not part of the XHTML document. It is neither an XHTML element nor a closure character.
Note: The xmlns attribute inside the <HTML> tag is required in XHTML. however, the validator on w3.org does not complain when this attribute is missing in An XHTML document. this is because "xmlns = http://www.w3.org/1999/xhtml" is a fixed value and will be added to the <HTML> tag even if you do not include it.
Note: The XML document requires the xmlns attribute to appear in the HTML Tag. However, the w3.org validity checker does not report errors for this attribute that does not appear in your XHTML document. This is because "xmlns = http://www.w3.org/1999/xhtml" is a fixed value that is automatically added even if it is not included in your document.
You will learn more about the XHTML document type definition in the next chapter.
In the next chapter, you will learn more about xhtl file type definition.
(For more information, see the source)