One of the best ways to learn HTML tricks and techniques is to view the HTML statements used
in Web pages you encounter as you surf the Web. To view the HTML source code for a Web page,
select View | Source from within your browser. (If you are using Netscape Navigator, select View |
Page Source.) As you examine Web pages, you will find that many HTML documents have a document
type tag (<!doctype>) at the start of the Web page.
The Document Type Definition (DTD) identifies the version of HTML used to create the
Web page. This information is important to Web browsers, HTML validation programs,
and to other software programs used for Web design and layout. To validate an existing HTML document
go to http://validator.w3c.org. The HTML validation program checks the organization and syntax of
the Web document based on the information supplied within the DTD. When the declaration indicates
that the document adheres to a strict version of HTML 4.01, the validator judges the Web page based
on the HTML 4.01 standard and generates a report with the results of the examination.
In the future, knowing the version of HTML used to create a page will help Web browsers and other
programs display Web pages with greater accuracy. In fact, the W3C considers a Web page created
with HTML version 4 as invalid unless the HTML document starts with a DTD. The DTD goes at
the top of the HTML document before the <html> tag. The following shows the correct format for
a typical DTD:
<!doctype html public "version name" "url">
• html Identifies the code as a version of the HTML.
• public Identifies the language as accessible by the public.
• version name Identifies the complete name for the specific version of HTML. For example,
the complete name for HTML 4.0 is -//W3C//DTD HTML 4.01 Transitional//EN.
• url Indicates where on the World Wide Web a public definition of the HTML code resides,
such as www.w3.org/TR/html4/loose.dtd.
A valid DTD for a Web page described using HTML version 4.01 would be as follows:
<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN"
"www.w3.org/TR/html4/loose.dtd">
The loose.dtd option in the previous code declares that the document may include all the elements
allowed in the HTML 4 “strict” standard, additional presentation description attributes, and may include
deprecated elements. Conversely, using strict.dtd in the DTD would declare that the document strictly
adheres to the HTML 4 standard. The strict version of HTML 4.01 emphasizes the structure of the
HTML document over the presentation of the page within the Web browser. This does not mean that
strict version of HTML 4.01 downplays the presentation of the Web page; it simply focuses on the
structure of the HTML markup code. Deprecated tags and elements such as frames and link targets
are not allowed in HTML strict. A third Document Type Definition, frameset.dtd, is used when
validating HTML documents containing frames.
Currently, neither Netscape Navigator nor Internet Explorer require that you include a DTD
before the start of your Web page HTML, that is, before the start HTML tag (<html>) at the top of
your Web document. However, you should include one at the start of any Web page you code using
HTML version 4.0 or later. The W3C is giving you a hint here. What is optional today may be required
in the near future. Therefore, stay ahead of the game and use the DTD in all your Web pages now.
0 comments:
Post a Comment