开发者

Which DOCTYPE declaration should we use?

开发者 https://www.devze.com 2023-01-21 04:44 出处:网络
I have read a number of books on DOCTYPE declaration and the three variations: strict, tra开发者_开发知识库nsitional and frameset.

I have read a number of books on DOCTYPE declaration and the three variations: strict, tra开发者_开发知识库nsitional and frameset.

But I am still not able to fully understand their difference and indeed am not sure which variation I should use when creating my website. In particular I don't understand the difference between strict and transitional.

could you please advise me?


Frameset is for documents that define framesets (non-frameset documents are then loaded into the frames). Frames are usually a poor design choice that cause more problems then they solve.

Transitional is, more or less, Strict plus things you shouldn't use (mostly because they have been replaced with CSS). There are a couple of exceptions, such as the start attribute which has some good arguments to support using it (but isn't often useful).

Strict is the core of HTML and is usually the best bet.

HTML 4.01 is the latest, finished version of HTML.

XHTML 1.0 is HTML 4.01 expressed in XML. It doesn't work in Internet Explorer unless you pretend it is HTML (which the text/html specification does allow).

XHTML 1.1 is XHTML 1.0 Strict plus the target attribute plus Ruby (not the programming language) plus a few other minor tweaks. There is no specification giving the OK to pretend XHTML 1.1 is HTML.

(Five years ago: HTML 5 is a draft specification, subject to change, and with many of the interesting bits not working without JavaScript backing them up in most browsers in use today. It lacks a mature validation tool.

HTML 4.01 is generally the best bet, but XHTML 1.0 is worth considering if you have an XML toolchain in your publishing system, and HTML 5 is worth considering if you have a need for something added in it and feel the risk of living on the bleeding edge is worth it.

In short: Use HTML 4.01 Strict unless you know why you need to use something else.)

Since this answer was originally written, HTML 5 has become a standard with good browser and toolchain support. It is the specification most closely aligned with how browsers actually work. An XML serialisation is available if you need XML support.

In short: Use HTML 5: <!DOCTYPE html>.


Use the HTML5 DOCTYPE:

<!DOCTYPE HTML>

Everything else is old and busted.

HTML5 > XHTML > HTML 4

Note: The DOCTYPE is only useful for validating your document and for triggering the most standards compliant mode in modern browsers. Other than that, it's worthless. So you might as well use the most modern version (HTML5).


First, are you using HTML or XHTML? I would recommend HTML - XHTML is a dead standard. HTML5 is the future (though who knows when that future will arrive) so I would go with HTML 4 transitional:

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

This is the closest commonly-supported doctype to HTML5. You can use features of HTML5 like the <menu> tag and it will still validate.

0

精彩评论

暂无评论...
验证码 换一张
取 消