开发者

Which html doc type should I use?

开发者 https://www.devze.com 2023-01-09 13:18 出处:网络
I\'m writing a web page. How do I know what doc type to use?: <!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">

I'm writing a web page. How do I know what doc type to use?:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

or

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

I believe the rationale behind using Transitional is that if your pa开发者_如何学JAVAge uses deprecated html elements, the browsers will try to support them?

Thanks


I'd use <!DOCTYPE html>, it's by far the easiest alternative, and it triggers standards mode in all modern browsers as Anne van Kesteren noted several years ago.


You should prefer strict above transitional/loose/invalid(!). Your first transitional example is invalid. It will let any browser render in non-standards/quirks mode, it won't let IE render in almost-standards mode.

This site contains excellent background information and a compatibilty table. Here's an extract of relevance:

Standards mode, more stable validation target

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

This doctype also triggers the standards mode, and the decade-old HTML 4.01 validity definition is stable. Please be sure to test your image alignment in Firefox, Safari, Chrome or Opera 9 or 10. Testing image alignment with Internet Explorer is inadequate however be sure to test in IE8, too.

You’d like to use the Standards mode, but you still want to validate deprecated markup or you use sliced images in table layouts and don’t want to fix them

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

This gives you the Almost Standards mode (and the full Standards mode in really old Mozilla releases). Please note that your layouts based on sliced images in tables are likely to break if you later move to HTML5 (and, hence, the full Standards mode).

I'd say, go for HTML5 doctype <!DOCTYPE html>, unless you want a more stable validation target.


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

HTML 4 Strict DTD if you

a) Don't plan on using HTML 5 elements

b) Don't plan on really using xhtml with Content-Type of application/xhtml+xml

In this day and age you really shouldn't be "transitioning" or trying to using old, deprecated non-standard elements. Go standard all the way.

If you do plan on trying out HTML 5, by all means just use <!DOCTYPE HTML> which is the HTML 5 DTD.

0

精彩评论

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

关注公众号