HTML and CSS Reference
In-Depth Information
Whereas some attributes are prohibited, others are required. A list of the required
attributes and the elements they're associated with is shown in Figure 9-10.
figure 9-10
Required XHtML attributes
Element
Required Attributes
applet
height,ƒwidth
area
alt
base
href
basefont
size
bdo
dir
form
action
img
alt,ƒsrc
map
id
meta
content
optgroup
label
param
name
script
type
style
type
textarea
cols,ƒrows
For example, an inline image is valid only if it contains both the src and alt attri-
butes, and a form element is valid only if it contains an action attribute.
Although the list of rules for well-formed and valid documents may seem long and
onerous, these rules simply reflect good coding practice. You would not, for example,
want to create a Web page without a page title, or an inline image without alternate text.
In addition to being required for valid well-formed code, there are many advantages to
using DTDs. Perhaps their most significant advantage is the help they provide in trouble-
shooting documents. If you create or edit your XHTML code by hand, you can easily
make mistakes in syntax, content, or structure. Using a DTD is required if you want to
test your document against the set of rules that govern XML.
Inserting the DOCTYPE Declaration
To specify which DTD is used by an XML document, you add a DOCTYPE declaration
directly after the XML prolog. The syntax is
<!DOCTYPEƒ root ƒ type ƒ“ id ”ƒ“ url ”>
where root is the name of the root element of the document, type identifies the type
of DTD (either PUBLIC or SYSTEM ), id is an id associated with the DTD, and url is the
location of an external file containing the DTD rules. For XHTML documents, you set the
root value to html and the type value to PUBLIC .
Figure 9-11 lists the complete DOCTYPE declarations for different versions of HTML
and XHTML. Note that you can validate a document not only against different versions
of XHTML 1.0, but even against different W3C specifications for HTML as far back as
HTML 2.0; this can be beneficial if you need to develop code for older browsers that do
not support current standards. You can access the most recent versions of these DTDs on
the W3C Web site.
Search WWH ::




Custom Search