1.Introduction To XHTML (1)What Is XHTML? XHTML stands for EXtensible HyperText Markup Language XHTML is aimed to replace HTML XHTML is almost identical to HTML 4.01 XHTML is a stricter and cleaner version of HTML XHTML is HTML defined as an XML application XHTML is a W3C Recommendation (2)XHTML 1.0 became a W3C Recommendation January 26, 2000. A W3C Recommendation means that the specification is stable, that it has been reviewed by the W3C membership, and that the specification is now a Web standard. W3C defines XHTML as the latest version of HTML. XHTML will gradually replace HTML. (3)Why XHTML? We have reached a point where many pages on the WWW contain "bad" HTML. XML is a markup language where everything has to be marked up correctly, which results in "well-formed" documents. Therefore - by combining HTML and XML, and their strengths, we got a markup language that is useful now and in the future - XHTML. 2.Differences Between XHTML And HTML (1).How To Get Ready For XHTML XHTML is not very different from HTML 4.01, so bringing your code up to the 4.01 standard is a good start. Our complete HTML 4.01 reference can help you with that. In addition, you should start NOW to write your HTML code in lowercase letters, and NEVER make the bad habit of skipping end tags like the </p>. (2)The Most Important Differences: XHTML elements must be properly nested <ul> <li>Coffee</li> <li>Tea <ul> <li>Black tea</li> <li>Green tea</li> </ul> </li> <li>Milk</li> </ul> Notice:every tag must to nested.the fllow code is wrong <ul> <li>Coffee</li> <li>Tea <ul> <li>Black tea</li> <li>Green tea</li> </ul> <li>Milk</li> </ul> (3).XHTML documents must be well-formed All XHTML elements must be nested within the <html> root element. All other elements can have sub (children) elements. Sub elements must be in pairs and correctly nested within their parent element. The basic document structure is: <html> <head> ... </head> <body onbeforeunload="RunOnBeforeUnload()" onbeforeunload="RunOnBeforeUnload()" onbeforeunload="RunOnBeforeUnload()" onbeforeunload="RunOnBeforeUnload()"> ... </body> </html> ***Tag names must be in lowercase This is because XHTML documents are XML applications. XML is case-sensitive. Tags like <br> and <BR> are interpreted as different tags. All XHTML elements must be closed Non-empty elements must have an end tag. This is wrong: <p>This is a paragraph <p>This is another paragraph This is correct: <p>This is a paragraph</p> <p>This is another paragraph</p> (4)Empty Elements Must Also Be Closed Empty elements must either have an end tag or the start tag must end with />. This is wrong : This is a paragraph<p> This is correct: This is a paragraph <p /> IMPORTANT Compatibility Note: To make your XHTML compatible with today's browsers, you should add an extra space before the "/" symbol like this: <br />, and this: <hr />. 3.XHTML Syntax Some More XHTML Syntax Rules: (1)Attribute names must be in lower case This is wrong: <table WIDTH="100%"> This is correct: <table width="100%"> (2)Attribute values must be quoted This is wrong: <table width=100%> This is correct: <table width="100%"> (3)Attribute minimization is forbidden 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" (4)The id attribute replaces the name attribute This is wrong: <img src="picture.gif" name="picture1" /> This is correct: <img src="picture.gif" id="picture1" /> 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="picture1" name="picture1" /> (5)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 add the xml:lang attribute, like this: <div lang="no" xml:lang="no">Heia Norge!</div> (6)The XHTML DTD defines mandatory 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. This is a minimum XHTML document template: <!DOCTYPE Doctype goes here> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Title goes here</title> </head> <body onbeforeunload="RunOnBeforeUnload()" onbeforeunload="RunOnBeforeUnload()" onbeforeunload="RunOnBeforeUnload()" onbeforeunload="RunOnBeforeUnload()"> Body text goes here </body> </html> Note: The DOCTYPE declaration is not a part of the XHTML document itself. It is not an XHTML element, and it should not have a closing tag. 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.
博客园 © 2004-2025 浙公网安备 33010602011771号 浙ICP备2021040463号-3