The Difference between HTML and XHTML
HTML and XHTML have very similar names; they have some interesting differences that you need to be aware of.
XHTML is a reformulation of HTML in XML — extensible Markup Language. This is a generic, text- and tag-based language used to describe data and is used as the base language for many other languages, including XHTML.
So, XHTML is in fact largely just HTML rewritten with XML rules. These rules are pretty simple, and most of the time VWD will help you get it right or show you a list of errors and suggestions on how to fix them.
1-Always Close Your Elements
In XHTML, all elements must be closed. So when you start a paragraph with <p>, you must use
</p> somewhere later in your page to close the paragraph. This is also the case for elements that don’t have their own closing tags, like <img> or <br> (to enter a line break). In XHTML, these tags are written as self-closing tags, where the closing slash is embedded directly in the tag itself as in
<img src=”Logo.gif” /> or <br />.
2-Always Use Lowercase for Your Tag and Attribute Names
XML is case sensitive, and XHTML applies that rule by forcing you to write all your tags in lo
Although the tags and attributes must be in all lowercase, the actual value doesn’t have to be preceding example that displays the logo image is perfectly valid XHTML, despite the upper the image name.
3-Always Enclose Attribute Values in Quotes
Whenever you write an attribute in a tag, make sure you wrap its value in quotes.
For example when writing out the <img> tag and its src attribute, write it like this:
<img src=”Logo.gif” />
And not like this:
<img src=Logo.gif />
You could also use single quotes to enclose the attribute value, as in this example:
<img src=’Logo.gif’ />
It’s also sometimes necessary to nest single and double quotes. When some special ASP.NET syntax requires the use of double quotes, you should use single quotes to wrap the attribute’s value:
<asp:Label ID=”TitleLabel” runat=”server” Text=’<%# Eval(“Title”) %>’ />
For consistency, this book uses double quotes where possible in all HTML that ends up in the client.
4- Nest Your Elements Correctly
When you write nested elements, make sure that you frst close the inner element you opened last, and then close the outer element. Consider this correct example that formats a piece of text with both bold and italic fonts:
<b><i>This is some formatted text</i></b>
Notice how the <i> tag is closed before the <b> tag. Swapping the order of the closing tags leads to invalid XHTML:
<b><i>This is some formatted text</b></i>
5-Always Add a DOCTYPE Declaration to Your Page
A DOCTYPE gives the browser information about the kind of HTML it can expect. By default, VWD adds a DOCTYPE for XHTML 1.0 Transitional to your page:
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN”
“http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
The DOCTYPE greatly influences the way browsers like Internet Explorer render the page. VWD’s default DOCTYPE of XHTML 1.0 Transitional gives you a good mix between valid markup and pages that render the same in all major browsers.
1 comments:
Check out the differences between html and xhtml in interactive and easy way.
Post a Comment