Course Technology Logo
     
Home 
Tutorials 
 Tutorial 1
 Tutorial 2
 Tutorial 3
 Tutorial 4
 Tutorial 5
 Tutorial 6
 Tutorial 7
 Tutorial 8
 Tutorial 9
 Tutorial 10

Data Files 

Tutorial 1: Developing a Web Page


The Core Attributes

HTML and XHTML support a wealth of attributes that can be applied to different elements in the document head and body. There are several attributes that are common to almost all page elements. These attributes are known as the standard, or core, attributes. The core attributes are: class, id, style, and title.

The class attribute is used to identify elements that belong to a certain class or group. The syntax of the class attribute is

class="text"

where text is the text of the element class. Several elements can share the same class. For example, the following code contains markup for two headings that both belong to the main class. Notice that the paragraph that follows is not part of the main class.

<h1 class="main">Dave's Devil Sticks</h1>
<h2 class="main">Home of the Light Styk</h2>
<p>Welcome to the Dave's Devil Sticks Web site.</p>

The class attribute is most often used with style sheets in order to assign a common design to groups of elements.

The id attribute identifies unique elements within the Web page and has the syntax

id="text"

where text is the id of the element. Unlike classes, ids must be unique and cannot be assigned to more than one element within the Web page.

The style attribute is used to apply an inline style to a page element, controlling how that element is presented by the browser. The syntax of the style element is

style="styles"

where styles is a semicolon-separated list of CSS styles. For example, the following code sets the font color of the h1 heading to red.

<h1 style="color: red">Dave's Devil Sticks</h1>

Finally, the title attribute provides a title for an element, having the syntax

title="text"

where text is the title text. Title text is often displayed by browsers as a Tooltip when the mouse hovers over the page element. In some applications, it is also used to bookmark elements for search engines and to document hypertext links.

XHTML doctypes

To convert an HTML element into XHTML, you can replace the opening <html> tag with the following three lines of code

<?xml version="1.0" encoding="iso-8859-1"?>
dtd
<html xmlns="http://www.w3.org/1999/xhtml">

where dtd is a document type declaration that defines the type of XHTML document for which the code is written. Every XHTML document has to be validated against a set of rules that define the language. The dtd statement indicates what kind of rules should be applied to the document. The general form of the dtd is

<!DOCTYPE root type "id" "url">

where root is the name of the root element of the document, type identifies the type of dtd being used, id is a recognized public identifier of the dtd, and url is the location of an external dtd file in which the rules of the language have been stored.

For XHTML documents, the root is always "html" and the type is "PUBLIC". The id and url values depend on the dtd being used. If the browser recognizes the id value, it uses that information to locate the external file containing the language rules. If the browser doesn't recognize the id value, it uses the url value to locate the external file.

The table below lists some of the common XHTML dtds. Note that you can validate a document not only against different versions of XHTML 1.0, but also against different versions of HTML, even down to the W3C's specifications for HTML 2.0. You can access the most recent versions of these dtds on the W3C Web site.


DTD DOCTYPE
HTML 2.0 <!DOCTYPE html PUBLIC "-//IETF//DTD HTML 2.0//EN">
HTML 3.2 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
HTML 4.0 strict <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
HTML 4.01 transitional <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
HTML 4.01 frameset <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">
XHTML 1.0 strict <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
XHTML 1.0 transitional <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
XHTML 1.0 frameset <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
XHTML 1.1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

Once you have converted an HTML document into XHTML, you can access tools on the W3C Web site to test your document, verifying that it is valid based on the rules of the language.

A second use for converting an HTML document into XHTML is that it tells the browser to apply a strict interpretation of the language rules. In order to be compatible with older code, many browsers will, by default, interpret HTML code very liberally. This can result in code that is technically incorrect, but still viewable in most cases. To force the browser to operate what is known as standards mode, you change the HTML code into one of the versions of XHTML by applying one of the dtds noted above.

Deprecated Elements

With the introduction of HTML 4.0 and XHTML 1.0, many older elements were deprecated in favor of style sheets. The purpose of deprecation is to flag those features of HTML that are being gradually phased out from support by the W3C and the browser market. Although deprecated elements can still be used in most cases, their use is discouraged. Most deprecated elements involve markup tags whose sole purpose is to describe how the page content should be rendered. However, HTML should be used only to describe document content, not how that content should be rendered. The following table lists the deprecated HTML elements.

Element Description
applet Java applet
basefont Defines a base font for the Web page
center Horizontally centers the enclosed content
dir Contains a directory list
font Sets the font properties of the enclosed content
isindex Provides a single line prompt to the user
menu Contains a menu list
s Marks the enclosed content as strike-through text
strike Marks the enclosed content as strike-through text
u Underlines the enclosed content

In addition to these deprecated elements, there are several elements that are not part of the W3C specifications, but were introduced and supported by specific browsers. Those elements should be avoided in any HTML code unless the audience is known to only use the browser supporting those elements.

Deprecated Attributes

Like deprecated elements, deprecated attributes represent those features of HTML that are being phased out, to be replaced by style sheets and XHTML. Most of the deprecated attributes involve document presentation and are known as presentational attributes. The following is a list of presentational attributes that should not be used in HTML code.

Attribute Description
align Java applet
alink Defines a base font for the Web page
archive Horizontally centers the enclosed content
background Contains a directory list
bgcolor Sets the font properties of the enclosed content
border Provides a single line prompt to the user
clear Contains a menu list
code Marks the enclosed content as strike-through text
codebase Marks the enclosed content as strike-through text
color Underlines the enclosed content
compact Java applet
face Defines a base font for the Web page
height Horizontally centers the enclosed content
hspace Contains a directory list
language Sets the font properties of the enclosed content
name Provides a single line prompt to the user
noshade Contains a menu list
nowrap Marks the enclosed content as strike-through text
object Marks the enclosed content as strike-through text
prompt Underlines the enclosed content
size Java applet
start Defines a base font for the Web page
text Horizontally centers the enclosed content
type Contains a directory list
value Sets the font properties of the enclosed content
version Provides a single line prompt to the user
vlink Contains a menu list
vspace Marks the enclosed content as strike-through text
width Marks the enclosed content as strike-through text

Specific browsers might also support attributes that are not part of the W3C standards but are in common use.