What DOCTYPE! to use for my site

That’s what I thought he was saying as well.

So although I was wrong saying the doctype is html5 specific, I do agree with ds60’s view and hence the second part of my comment:

Except that if the page doesn’t have any html5 specific elements, then the html5 doctype declaration is really meaningless and causes markup validation issues.
and so I wouldn’t recommend using it unless there is no other option of course.

But the point is, it’s not an HTML5 specific doctype. All HTML elements are covered by that doctype; and HTML5 is not a new animal: it’s just HTML with a few new elements. The doctype will continue to be the same even as further elements are added (even if they get collectively dubbed “HTML6” or whatever). I’m not sure what markup validation issues you might be referring to.

Basically you need some kind of doctype to prevent the browser jumping into quirks mode, but which you use doesn’t seem to matter a whole lot.

ok maybe I’m misunderstanding something here.

I totally agree that a doctype must be used. But I am under the impression that if you have html5 specific elements in the html then <!DOCTYPE html> must be used and that if you don’t have any html5 specific elements then you shouldn’t use <!DOCTYPE html>, but instead use either the Strict doctype for either html or xhtml, depending on your code.

The validation issues I refer to if using <!DOCTYPE html> are the same as mentioned by ds60 in the other thread and also I note that the w3c validator also mentions that its validation results for doctype <!DOCTYPE html> should not be relied upon for now at least.

I guess what I am saying is that if I stick <!DOCTYPE html> on top of my html or xhtml code that doesn’t contain any html5 elements, I am under the impression that the w3c validator might not detect errors in the code it otherwise would if using one of the Strict doctypes instead. Is my perception correct?

No, it’s fine to use the new doctype for any kind of site now, as many are doing. It’s neater and simpler and has no negative side effects. That doctype covers all HTML elements.

I guess what I am saying is that if I stick <!DOCTYPE html> on top of my html or xhtml code that doesn’t contain any html5 elements, I am under the impression that the w3c validator might not detect errors in the code it otherwise would if using one of the Strict doctypes instead. Is my perception correct?

In my experience, it has certainly picked up any errors that I’ve made with no problem. Of course, because it is not bound to some of the stricter rules of XHTML*, it won’t hassle you about things like unclosed elements like LIs etc. (so I believe, anyhow, as I never leave elements unclosed). Perhaps when the w3c says it’s not totally reliable yet it means in terms of the newer elements that aren’t really real-world ready yet.

If you are worried, you could always swap to another doctype for validation purposes. But then I guess you might as well be done with it and use that other doctype anyway. I’ve just converted to the simpler doctype because I don’t use XHTML anyway and because it’s much neater.

There are people around here who know far more than me about all this stuff and have argued passionately against the merits/worthiness of the new doctype, but I’ve given in now, as I like it’s simplicity and I’ve found no problems with its use at all.

*EDIT: actually, I may be wrong there anyway, as there is also XHTML5. Perhaps that’s a different option to validate against, but I haven’t checked.

If someone is not concerned if their code validates or not then I suppose you can use the doctype on any document.

But I just did a little experiment to confirm what you said about it not hassling you about some unclosed elements. In this sample code

<!DOCTYPE HTML>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
        <title></title>
    </head>
    <body>
        <ul>
            <li>item 1
        </ul>
    </body>
</html>

the w3c validator passes it without any errors even though a Strict html or xhtml doctype would have generated a validation error due to the missing </li>

For me, who likes the rigidity of xhtml, the fact the w3c validator passes the above code is a deal breaker for using the above doctype unless there is no another option, like when using html5 specific elements.

I also note that on the w3c valid doctypes page it lists <!DOCTYPE HTML> as being for HTML5 only and also states that it is not standard yet. However, it doesn’t say it cannot be used for other documents as well. But by not listing it for the other document types, I guess they are indirectly discouraging the use of <!DOCTYPE HTML> for anything other than documents that contain html5 specific elements.

Which is perfectly fair enough. For me, because I never am likely to leave elements unclosed etc. that doesn’t bother me. I’m more liley to make a typo, which the validator would pick up.

I’m also unlikely to leave elements unclosed, especially since my IDE (netbeans) automatically inserts the closing tag when I type in the opening tag. But if someone is using just a basic text editor they are much more likely to have unclosed tags and if they use <!DOCTYPE HTML> and see it passing the w3c validator (with unclosed tags and possibly other undetected errors) they then often wander into forums like this one in tears and with their code dragging along the ground behind them and ask “Why isn’t my page working in such 'n such browser?” :bawling:

If someone insists on using <!DOCTYPE HTML> for html4 or xhtml docs, I am not going to say they must not use it, but I think we (colectively) should at least point out the potential pit falls and not necessarily given them carte-blanche to use <!DOCTYPE HTML> in all documents.

Usually the doctype they are using is the least of their worries. Many have never heard of a validator anyway, or a strict doctype. :lol:

Not necessarily.

The point I was making is that if they didn’t use <!DOCTYPE HTML> when they didn’t have to and instead used a more appropriate doctype for their web page, the validator would have picked up the error and they, in many cases, would then fix the problem straight away rather than spend time going to a forum asking for help on why their page doesn’t work even though it passed the validator and so not giving them a reason to look closer at their code for the cause of the problems.

Great information - thank you. I still don’t have the solution however. <!DOCTYPE HTML> does not work for my site.

The only doctype I can find that works is <!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=“http://www.w3.org/1999/xhtml”>

This is an older site FYI. Not a newly created one.

Should I assume this character encoding along with it? content-type: text/html; charset=ISO-8859-1

The <!DOCTYPE html> option was first introduced in HTML 2. The only difference when you use that rather than the longer version with HTML 2, 3.2 or 4 is that you are not specifying which version of SGML compliant HTML that you are using. It is simply the short version of the SGML tag identifying the content of the file as HTML. With HTML 5 they have dumpled the markup standards from SGML and added that tag into HTML itself. So you can either use a standards compliant version of HTML with that tag or a more recent version of HTML that doesn’t bother with following the standards and use the same tag even though it means something completely different.

Presumably once HTML 5 becomes a standard (if it ever does given that almost everyone is still using HTML 3.2) they will then change the doctype so as to distinguish between pages that follow the finished standard from those that follow something from the draft version that doesn’t end up in the final standard. After all It was the IE5 implementation of the box model from an early draft of CSS2 that led to browsers having to check for the doctype tag in the first place in order to distinguish between pages written to follow that early draft from pages written to follow the completely different final standard.

The HTML standards have nothing to do with the <!DOCTYPE html> tag except for HTML 5 where it is defined as a part of the HTML. Wikipedia has a reasonably accurate description of SGML at http://en.wikipedia.org/wiki/Standard_Generalized_Markup_Language where you can find out what the doctype tag really means for all documents that are not HTML 5.

Thanks felgall. Could you explain a bit more about what this means:

In what way have they dumped standards? Do you mean various elements now have different rules, or something more fundamental?

Also not quite sure what adding the tag to the HTML means.

Will try to go through that WikiPedia article, but I think I’ve looked through it before. All this stuff seems like Double Dutch to me.

There is a standard for defining markup languages that is called SGML. All of the versions of HTML between 2 and 4.01 have been defined using that standard - hence they are allowed to have an SGML doctype at the top of the document that defines just what type of document they are. The optional parts of the doctype include having a link to the definiition of the markup language - for example http://www.w3.org/TR/html4/strict.dtd is the definition according to the SGML standards of HTML 4 strict. Now if the browsers were going to use the doctype properly they’d use that file as the definition of what tags and attributes that the language allows and would refuse to display any page that contained something non-standard - none of the browsers actually work that way though as some that are still in use were originally created before HTML2 and HTML 1 didn’t follow the standards - the other browsers need to be as forgiving of garbage in order to compete. One of the biggest changes in HTML 2 was to redefine HTML in accordance with the SGML standards. One of the biggest changes in HTML 5 was the decision that since the browsers ignore the true meaning of the doctype and only use it as a switch for pages that followed draft versions of standards that they would abandon defining HTML 5 in accordance with the standards and just provide something that looks like the SGML standards definition at the top in its place to use as the switch - of course since HTML 5 is still in draft they’ll need another switch to handle the difference between the current draft and whatever comes next - obviously not a standard since HTML 5 isn’t bothering with standards.

Thanks Stephen. Interesting anwser, as always. :slight_smile: I don’t see why another switch will be needed later, though. Doesn’t that simpler doctype cover all versions?

That’s because your site is XHTML transitional. Transitional because you mix strucuture and presentation… XHTML because empty tags such as link, or img are closed with />

Exmaple of image in any version of html:

<img src="whatever.jpg" alt="alternative text">

but in XHTML,

<img src="whatever.jpg" alt="alternative text" />

Thanks molona,
Is my site fine leaving it this way then?

If you’re not going to change the code to make it more appropriate to today’s standards, yes, it is fine to leave it like that. :slight_smile:

I am a newbie - anxiously learning but not quite at the point of being able to change this code appropriately. I am working on it though!

At least I did learn a lot from this forum including to change my title tag (learned it was way to long) and that meta keywords are ignored.

Your time and knowledge is most appreciated. Thank you.

That doctype doesn’t allow browsers to distinguish between pages written following the current draft version of HTML 5 from those following the final standard where some of the tags will likely end up meaning something completely different.

It has happened before where IE5 implemented some CSS 2 while it was still a draft and the final version was different - that’s why browsers since then use the presence or absence of the doctype as a switch in the first place.