Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
449 views
in Technique[技术] by (71.8m points)

html - Which DOCTYPE declaration should we use?

I have read a number of books on DOCTYPE declaration and the three variations: strict, transitional 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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>.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...