Rule #2: Explicitly version your HTML documents.
Explicitly declare the Document Type Definition (DTD) for each page, the character set the browser should use, the stylesheet formatting technique, and watch your client-side <script> tags. The newer the target browser is, the more it will comply with explicitly declared types to visually represent your document. Otherwise, each browser will default to its own types, eliminating your control.
XML and Document Type Definitions
XHTML. A new web page should loosely comply with XHTML specifications. For XHMTL, the XML declaration is the first line of the page and the the DTD immediately follows. Here 's the XML declaration for a static XHTML page. Check your platform documentation for its procedure of server-side XML declaration:
<?xml version="1.0" encoding="iso-8859-1"?>
Here's the DTD and corresponding <html> tag:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
HTML. Old web pages can comply with the HTML 4.01 Specification. This is to avoid a complete recoding of existing pages. You should also run these pages through an HTML validator to eliminate, at least, any pre-4.01 markup. You only need the DTD, no XML declaration or special HTML tag required:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
If you can't find a way to get your code to format consistently cross-browser using this rule, you should alter your design or HTML code to compensate, not your DTD.
HTTP content types
In addition to the the DTD and XML declarations, the following meta tags need to be somewhere in the <head></head> . The first line tells the browser which character set to use, the second line tells the browser what kind of style sheet we use:
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
Client-Side Scripting
Client-side JavaScript is included in a web page with the <script></script> tag. Here's the current way to do it:
<script type="text/javascript"></script>
The <script></script> tag used to require the attribute language. This is no longer necessary for either HTML 4.01 or XHTML 1.0. Version can't be declared in the HTML <script></script> tag in a cross-browser way.