HTML
HTML introduction
HTML basics
HTML colors
HTML backgrounds
HTML text
HTML font
HTML text formatting
HTML entities
Display tags
HTML links
Email links
Types of links
HTML images
HTML image maps
HTML tables
HTML frames
HTML forms
Fieldset/legend tags
HTML stylesheets
Div/span tags
HTML layout
HTML marquees
HTML multimedia
HTML meta tags
HTML document types
HTML base tag
HTML scripts
URL formatting
Encoding and decoding
HTML summary

Programming

Programming intro
Java

Markup

First webpage guide
XHTML

Style & Layout

CSS

Browser scripting

Javascript
VBScript
AJAX

Server scripting

PHP
ASP

Making money online

Make money online

HTML document types

There are three document type definitions in HTML. Each document type definition specifies what type of document an HTML document will be.

This lesson focuses on:

Specifying a document type definition

A document type definition is specified with the <!DOCTYPE> declaration. The <!DOCTYPE> declaration should be the first line of code in an HTML document, even before the <html> tag.

NOTE: The <!DOCTYPE> declaration is mandatory and should always be the first thing in an HTML document.

NOTE: Although a document type definition is technically not required for a functioning webpage, it is good practice to always include it in your webpages. As you learn to build webpages, get into the habit of always including the document type definition in your code.

Example:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Specifying a document type</title>
</head>
<body>
</body>
</html>

The line of code that specifies the document type definition is:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
"http://www.w3.org/TR/html4/loose.dtd">

The rest of the HTML document:

<html>
<head>
<title>Specifying a document type</title>
</head>
<body>
</body>
</html>

The Transitional document type definition

The Transitional document type definition specifies an HTML document that uses some deprecated features such as the <font> tag, and can also be used for documents that will be displayed in browsers that do not support Cascading Style Sheets.

Example:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Specifying a document type</title>
</head>
<body>
</body>
</html>

The Frameset document type definition

The Frameset document type definition specifies an HTML document that uses frames to display one or more pages at the same time in the browser window. The Frameset document type definition is similar to the Transitional document type definition, but unlike the Transitional document type definition, the Frameset document type definition uses the <frameset> tag instead of the <body> tag.

Example:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" 
"http://www.w3.org/TR/html4/frameset.dtd">
<html>
<head>
<title>Specifying a document type</title>
</head>
<frameset cols="50%, 50%">
<frame src="frame1.php" />
<frame src="frame2.php" />
</frameset>
</html>

The Strict document type definition

The Strict document type definition specifies an HTML document that contains really clean markup with no presentational clutter, and does not use any deprecated features such as the <font> tag. The strict document type should be used together with Cascading Style Sheets.

Example:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" 
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Specifying a document type</title>
</head>
<body>
<h1>Content</h1>
</body>
</html>

Examples

Transitional document
This example demonstrates creating a transitional HTML document.

Frameset
This example demonstrates creating a frameset HTML document.

See more document type examples

Practice

Online code editor
Practical examples
Practical exercises
Step-by-step tutorials

Reference

Terms glossary
Reference material

Rate this site

Rate this site
Visitor comments