[LBSC 690] DOCTYPEs for HTML pages

0 views
Skip to first unread message

William Webber

unread,
Feb 23, 2012, 12:29:04 PM2/23/12
to lbsc690-sp...@googlegroups.com
Hi all!

After marking the Homework 3 assignments (the basic HTML page), I've
had a <i>mea culpa</i> moment: just because I've spent the past 15
years writing invalid HTML, doesn't mean I should teach you to do so,
too.

In particular, I think we should start including the DOCTYPE header
in our HTML pages. This tells the browser (and any other interested
parties) what version of HTML our page is adhering too. Most importantly,
this also means that when we submit our pages to the w3 validator:

http://validator.w3.org/

we actually have a chance of having no errors (because the validator
requires a DOCTYPE declaration).

So, at the top of each HTML page, before the opening <html> tag,
place:

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

for HTML. If you want to try XHTML instead, use:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

(If you don't know the difference between HTML and XHTML, just use
HTML). Also, if you want also to avoid warnings from the validator, then
place:

<meta http-equiv="content-type"
content="text/html;charset=utf-8">

within your <head></head> tag to report the character set. See:

http://www.w3.org/QA/2002/04/valid-dtd-list.html

for a list of doctypes, and:

http://en.wikipedia.org/wiki/Document_Type_Declaration

for a brief explanation of them.

Once the DOCTYPE headers have been added, you should use the
w3 validator on your pages, and try to fix all errors it finds. This is
can be an interesting (i.e. frustrating) debugging experience, but it
is good experience. One tip is that an actual error in one part of
the page can spark off spurious errors in other parts, so try to fix
the first bug first, then retest the page and see if the others disappear.

William

Reply all
Reply to author
Forward
0 new messages