PDA

View Full Version : doctype


chrismiceli
05-08-2003, 12:38 AM
What does the doctype do, does it tell the browser which language to rendor the page in, or is it just for validating porpuses?

pardicity3
05-08-2003, 12:55 AM
Taking from http://www.w3schools.com/xhtml/xhtml_dtd.asp (XHTML is mentioned, but it doesn't really matter too much, this applies to HTML too):


DTD specifies the syntax of a web page in SGML
DTD is used by SGML applications, such as HTML, to specify rules that apply to the markup of documents of a particular type, including a set of element and entity declarations.
[X]HTML is specified in an SGML document type definition or 'DTD'.
An [X]HTML DTD describes in precise, computer-readable language the allowed syntax and grammer of [X]HTML markup

You almost had it right. It not only tells the browser which language to render in, it tells it how to render that language. An example is the XHTML box model. Without a DTD IE for windows renders a box different than it does with a DTD.

You do need a DTD to validate but his is just so that the validator can tell what language you are using.

In case you were wondering or find it interesing, you can go to the link that is specified through the DTD. For example, the link for an XHTML 1.0 strict DTD points to http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd . That is the stuff that tells the browser what to do :)

brothercake
05-08-2003, 03:09 PM
The DTD does not tell the browser what to do, and it doesn't say anything at all about how elements should be rendered. Doctypes do make a rendering difference (so-called "doctype switching") but there's nothing in the DTD that says that should happen - browser vendors have chosen to do that (and imo it's a bad choice).

DTD just defines the syntax - "element x can contain mixed data and the following attributes .." or "element y can only contain character data"

I think the easiest way to understand DTD is to come at it from XML - http://www.w3schools.com/dtd/default.asp

pardicity3
05-08-2003, 09:22 PM
:rolleyes: I knew I was being a little over-confident in trying to answer that question....serves me right...:o

I did a pretty bad job of explaining it...but anyway, exactly how does a DTD make a difference in rendering? I know it makes a difference with the box model in some browsers, but what exactly is making this happen? I realize that DTD's just say what attributes can go with what tags and the like, but I thought there was something else that cause the different redering.

jkd
05-08-2003, 09:42 PM
It is hardcoded into the browser itself to examine the doctype and possibly adjust it's rendering to account for it. It is a hack that often makes bad code, e.g. the overwhelming majority of the Internet, still render in browsers that claim to be standards compliant.

In other words, if the browser didn't purposely break its rendering, most webpages online will render properly, but in a way ranging from slightly to grossly unintentionally.

brothercake
05-08-2003, 09:48 PM
More info http://gutfeldt.ch/matthias/articles/doctypeswitch.html

pardicity3
05-08-2003, 10:03 PM
Good stuff brothercake. Much appreciated. ...I love being in the know...