0

I have a question regarding html doctype, is the url for doctype necessary? I saw it in some production codes that has only

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

without the URL like

"http://www.w3.org/TR/html4/loose.dtd">

I understand that doctype will let browser determine layout mode, either standard or quirk mode, but im uncertain whether do we need the url, does it make difference without the url?

3
  • Which HTML version/s do you need compatibility with?
    – Paul S.
    Dec 21, 2015 at 3:05
  • HTML 4.01Transitional.
    – hades
    Dec 21, 2015 at 3:07
  • Yes, it makes a big difference. With the 4.01 Transitional PUBLIC part, but without the URL, the document will be in quirks mode, With both, the document will be in almost-standards mode. With neither, the document will be in standards mode. See the rules at w3.org/TR/html51/syntax.html#the-initial-insertion-mode
    – Alohci
    Dec 22, 2015 at 0:52

4 Answers 4

2

The DOCTYPE header tells your browser what version of html the webpage is written in..Hence the browser will try to interpret the content of the page based on the version...with html4 and below the doctype string is needed.

However With HTML5 there is no need for a reference string..you can simply use

<!doctype html>

short simple and easy

(The DOCTYPE is retained in HTML4 as a "mostly useless, but required" header only to trigger "standards mode" in common browsers)

1
  • i see, just did a search and found this to support your statement, "Doctypes from earlier versions of HTML were longer because the HTML language was SGML-based and therefore required a reference to a DTD. This is no longer the case and the doctype is only needed to enable standards mode for documents written using the HTML syntax. Browsers already do this for <!DOCTYPE html>." - source w3.org/TR/html5-diff
    – hades
    Dec 21, 2015 at 3:16
1

It is valid HTML 3.2 to omit the URL. Probably not valid HTML 4 however

source

1

If you have noticed <!doctype html>, that's to indicate HTML5.

Doctype has a public identifier (e.g. -//W3C//...) followed by system identifier (e.g. http://www.w3c...). Notice that HTML2 and HTML3.2 had no system identifier (http://www.w3.org/QA/2002/04/valid-dtd-list.html). Otherwise you have to use a system identifier URL to call the doctype correct.

http://www.w3schools.com/tags/tag_doctype.asp provides some more literature regarding doctypes. Also note an interesting list of doctypes here: https://www.totalvalidator.com/support/doctypes.html. W3C documention is here: http://dev.w3.org/html5/html-author/

0

In HTML 4.01, the <!DOCTYPE> declaration refers to a DTD, because HTML 4.01 was based on SGML. The DTD specifies the rules for the markup language, so that the browsers render the content correctly.

HTML5 is not based on SGML, and therefore does not require a reference to a DTD.

but add the <!DOCTYPE> declaration to your HTML documents, so that the browser knows what type of document to expect.

Like as follows :

<!Doctype html>

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

This DTD contains all HTML elements and attributes, INCLUDING presentational and deprecated elements (like font). Framesets are not allowed.

2
  • This does not answer the question.
    – Alohci
    Dec 22, 2015 at 0:45
  • If for some reason you MUST use strict HTML 4.01 Transitional then you have to use full doctype declaration with the URL. However, if you just want something that triggers fully standards mode in the user agents (web browsers) go with HTML5 and use plain <!doctype html>. The HTML5 doctype was selected to be shortest string possible that's still looks sensible and at the same time triggers "standards mode" in all browsers. Jan 30, 2020 at 9:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.