It is good practice to validate Web pages so that there are no errors in your code. Here we will use the W3C's online HTML Validator using the HTML 4.01 Transitional DocType. Additionally, pages using any external, internal, or local cascading style sheets (CSS) done should also validate, according to the W3C's online CSS Validator using CSS version 2. These validators, and other useful tools, are found at http://www.w3c.org/
Note that even though a page's HTML code or CSS may validate with no errors, the page may still contain other errors. These validators will not know if your paths are incorrect, for example.
If you put validator buttons on your page, you can validate the page by simply clicking on the button!
1) Add the DocType Declaration for “HTML 4.01 Transitional” to your page.
To do this, place the following line of code at the very beginning of your
document,
before the <html>
tag:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
Note: if your page contains a <frameset>
tag, you must use
the "HTML 4.01 Frameset DTD" instead. See the validating
framesets section below.
2) Add the character encoding meta tag to your page. To do this, place the
following line of code in the <head>
section of your document:
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
3) Upload your page to the Web server.
4) View your page (the page on the server, not the page on your disk) in a Web browser. (If the URL that you see in the browser's address window starts with "file://" instead of "http://", it means that you are viewing a page that is on your own local disk, and not a page that is on a Web server.)
5) If you have placed buttons or text links on your page that link to the W3C's HTML validator, simply click on the button and see what the validator says about the HTML of your page.
If you do not have validator links on your page, copy your page's URL from the browser's address window. Then go to the online HTML Validator. (Note: if the W3C's HTML Validator site site is down, see the alternative validator site section below.) In the Validate by URI section, paste the URL of your page into the Address field. Click the Vaildate this page button.
6) If there are any errors, correct them, re-upload the page, and validate it again.
All <img>
tags require an alt
attribute, an
alternative text description of the image, as shown below:
<img alt="dog" src="dog.gif">
For invisible pixels used as spacers or shims, use the empty alt
value (nothing between the quotes) as shown below:
<img alt="" src="cleardot.gif">
All <area>
tags (used in imagemaps) require an alt
attribute, as shown below:
<area alt="dog" shape="circle" coords="97,58,57"
href="dog.html">
All <form>
tags require an action
attribute.
Normally the value of the action
attribute is the path to a CGI
script. However, if your form is not meant to be processed by a CGI script (perhaps
it is meant to be used with JavaScript), use the empty action
value
(nothing between the quotes) as shown below:
<form action="">
If you use JavaScript, your <script>
tag needs to have a
type
attribute:
<script type="text/javascript" language="javascript">
A frameset page will not validate according to the HTML 4.01 Transitional DTD.
On a page with a <frameset>
tag, you must use the "HTML
4.01 Frameset DTD" instead. On your frameset, or "parent,"
page, place the following code at the very beginning of your document, before
the <html>
tag:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN"
"http://www.w3.org/TR/html4/frameset.dtd">
Note that any "child" pages that appear in the frames of a frameset page are still standard Web pages, and should use the standard HTML 4.01 Transitional DTD. Only a frameset page uses the HTML 4.01 Frameset DTD.
If your frameset page uses the <noframes>
tag, the <noframes>
section must be within a <frameset>
section or the page will
not validate.
If you cannot connect to the W3C's HTML Validator site, try again after a few
minutes. If the site is still down, try their UK miirror site at:
http://www.mirror.ac.uk/services/validator/
Enter the URL of the page you wish to validate into the "Location" box, and click the "Validate this page" button.
1) If your page uses any external, internal, or local CSS, you must also make sure your CSS validates (even though the HTML Validator may say your page has no HTML errors, your page may still contain CSS errors).
2) View your page (the page on the server, not the page on your disk) in a Web browser. (If the URL that you see in the browser's address window starts with "file://" instead of "http://", it means that you are viewing a page that is on your own local disk, and not a page that is on a Web server.)
3) If you have placed buttons or text links on your page that link to the W3C's CSS validator, simply click on the button and see what the validator says about the CSS used by your page.
If you do not have validator links on your page, copy your page's URL from the browser's address window. Then go to the online CSS Vaidator. In the Validate documents by URI section, enter the URL of your page (or the address of your external style sheet) into the field. Leave the Profile on CSS version 2. Click the Submit this URI button.
4) If there are any errors, correct them, re-upload the page, and validate it again.
Note that when you use the CSS validator to check a page that does not have a link to an external style sheet and does not contain an internal style sheet, you will get a warning that says: "No style sheet found." This is OK; it will still check any local styles. But if you get the "No style sheet found" warning and you are linking to an external style sheet, then your path to the external style sheet is incorrect.
If you use CSS to specify the color of an element, you should also use CSS
to specify the element's background color. If you don't want to specify a custom
background color, you can use:
background-color: transparent