Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Correct Order of Elements in Valid HTML 3

Status
Not open for further replies.

djs45uk

Technical User
Nov 7, 2004
103
GB
Hi All

I am trying to validate my HTML with the W3C validator but it is proving to be more difficult that I thought.

In particular, I am getting lots of "document type does not allow element here" messages. Please can you tell me the correct order that elements should appear on an valid HTML page.

My HEAD is currently looking like this

Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD><TITLE>Webpage</TITLE>

<META name="author" content="">
<META name="title" content="">
<META name="description" content=""> 
<META name="keywords" content="">
<META name="generator" content="MSHTML 6.00.2900.2523">
<META http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<LINK href="style/style.css" type=text/css rel=stylesheet>

<SCRIPT language=JavaScript type=text/JavaScript>
<!--

javascript functions here

//-->
</SCRIPT>

<style type="text/css">
<!--
body {
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
}
-->
</style>

</HEAD>

Many thanks
Daniel
 
I initially took your code, added the following to it:
Code:
<body><p>Hello</p></body></html>
Then I set about moving all the tags to lower case and adding " quotes where they were not present.

The page validated.

I then went back to your original code and pasted it "as is" (with just the addition of the <body> etc).

The page validated.

So it appears that the page is fine.

Cheers,
Jeff

[tt]Jeff's Page [/tt][tt]@[/tt][tt] Code Couch
[/tt]
 
Yep.

You must have at least
Code:
<html>
<head>
</head>
<body>
</body>
</html>

In any HTML document.
In fact, you may need the title too, I can't remember.

Foamcow Heavy Industries - Web design and ranting
Target Marketing Communications - Advertising, Direct Marketing and Public Relations
I wonder what possesses people to make those animated gifs. Do you just get up in the morning and think, "You know what web design r
 
Thank you both - but that wasn't actually my page - I just sketched out a simple HTML head to check if the elements are in the right order (if there is an order).

Thanks for checking it out - I guess they are ok. That must mean all my errors are caused elsewhere.

Thank you for your help. I'll keep at it.

Daniel
 
You will probably find that there is just 1 actual erroneous tag that causes the parsing to go "out of synch".
Fix that and most if not all the errors will disappear.

Foamcow Heavy Industries - Web design and ranting
Target Marketing Communications - Advertising, Direct Marketing and Public Relations
I wonder what possesses people to make those animated gifs. Do you just get up in the morning and think, "You know what web design r
 
Since I've been doing fine financially lately, let me add my 2 cents to the pot.

I believe a great start to validation is knowing what you are validating against. This will help you understand why you can use something at one time and cannot at another (with diferent doctype). Doctype declaration tells the browsers (and subsequently the validator) to which standards your page adheres. Validator will like your doctype and understand it as html 4.0 transitional while browsers will see their opportunity and ignore the doctype because it is incomplete. I suggest you put one of the doctypes mentioned on this page at the top instead of yours:
Now that we have the correct doctype, we can begin examining the code. Jeff gave you some good suggestions and great coding practices for the future, however some of them (lower case for one) are not necessary if you're using html 4. So, while it is probably good if you force yourself to use lower case (for the sake of xhtml) it is not necessary if you're planning on just making one website and your editor insists on upper case.

As for the "correct order", there is no correct order how to make websites (then all would look very similar), but there are rules what goes where. Some of them will seem very logical (table cell only inside table row), others will become logical as you understand more html (table cannot be in font or link tag).

Finally, I am completely confused as to what your posting here was meant for. You gave us a mock code that more or less validated while you had your own code which did not validate. If you just wanted to know where certain elements go, you should tell us which are your offending elements and where do they appear offensive. This way we could help you more. If you want us to explain where every little element belongs, I am afraid we cannot do that. There's way too many. Studying the doctype could be a long process, but will give you exactly what you want.

P.S.: Foamcow, if I am not mistaken (I could be, since I too lazy to check), html documents are happy with the structure you provided while xhtml also require title.
 
Please don't be completely confused. I do not want you to explain where "every little element belongs".

I simply asked if there was a rigid structure in which the elements in the <HEAD></HEAD> has to be in.

I have validated the page now. Thank you very much babyjeffy and foamcow - your help is really appreciated.

Daniel
 
You can put the elements in the <head></head> in any way you want.

There are different rules, based on what you validate against, as vragabond stated above.

if you validate for XHTML, you have to have all tags in lowercase, as well as you have to close all tags.

tags which normally arent closed, like <br> => <br />
Also, if validating for xhtml, you will most likely get loads of errors on design-related properties, which you then have to move to the css-file.
the css fine (if you have one), should also be validated.

Olav Alexander Mjelde
Admin & Webmaster
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top