DOCTYPE HTML in html file - html

Why is <!DOCTYPE html ... > used in html file?
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

The DOCTYPE Declaration (DTD or Document Type Declaration) does a couple of things:
When performing HTML validation testing on a web page it tells the HTML (HyperText Markup Language) validator which version of (X)HTML standard the web page coding is supposed to comply with. When you validate your web page the HTML validator checks the coding against the applicable standard then reports which portions of the coding do not pass HTML validation (are not compliant).
It tells the browser how to render the page in standards compliant mode.
For more information refer to this "<!DOCTYPE html>" What does it mean?

It tells the browser that the following code is to be treated as a particular version of html code.
The browser knows then to look for an open HTML tag <html> and treats everything like html until it reaches the close HTML tag </html>
<!DOCTYPE html> is all that's needed now.

The term DOCTYPE tells the browser which type of HTML is used on a webpage. Here is link of official page which explains your query why and what is
<!DOCTYPE html>

A doctype defines which version of HTML/XHTML your document uses. You would want to use a doctype so that when you run your code through validators, the validators know which version of HTML/XHTML to check against

The declaration is not an HTML tag; it is an instruction to the web browser about what version of HTML the page is written in.
In HTML 4.01, the 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.
Tip: Always add the declaration to your HTML documents, so that the browser knows what type of document to expect.

The <!DOCTYPE html> declaration is used to inform a website visitor's browser that the document being rendered is an HTML document. While not actually an HTML element itself, every HTML document should being with a DOCTYPE declaration to be compliant with HTML standards.
For HTML5 documents (which nearly all new web documents should be), the DOCTYPE declaration should be:
<!DOCTYPE html>

Show to the browser than the file is a HTML5.
Is followed by the lenguage etiquete according to HTML5 good practiques.
<!doctype html>
<html lang="es">
In this case the second line indicates to the browsers than the file is in example, spanish in this case <html lang="es">

is important for building an HTML documents it is not just HTML but it is an instruction to the web browser about what version of HTML the page is written in.

Related

Difference in DOCTYPE's

I am new to HTML concepts, but I had issue with my web page. It was not able to load properly on IE10 then I googled further and changed the doctype from
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
to
<!DOCTYPE HTML>
surprisingly it worked
I tried reading regarding this DOCTYPE got to know that the mentioned DTD is used to render the web page. But i was not able to gather much information. can anyone tell me what is actually making the difference there ??
According to HTML standards, each HTML document requires a document type declaration. The "DOCTYPE" begins the HTML document and tells a validator which version of HTML to use in checking the document's syntax.
Doctype you used earlier :-
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
as you can see belongs to html 4
and doctype you used later
<!DOCTYPE HTML>
is HTML 5. the latest standard for web. That's why it's working in IE10.
The difference is HTML 4.01 and HTML 5. The doctype for HTML 5 is simply:
<!DOCTYPE HTML>
There could be many different reasons for why the rendering is different. For a well formatted HTML 4 document there shouldn't be any difference between HTML 4 and HTML 5. But if you are using HTML 5 features then declare the document as HTML 4 you may be triggering quirks mode.
"Quirks" mode is what browser manufacturers call when they need to emulate features of older versions of the browser engine including bugs (yes, emulate bugs, because some web developers use bugs to trigger features in their code). You can think of quirks mode as HTML version custom-to-this-browser-and-only-this-browser.

Necessary for the URL in html DOCTYPE?

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?
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)
It is valid HTML 3.2 to omit the URL. Probably not valid HTML 4 however
source
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/
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.

How can I tell if the following Web page source code is XHTML, HTML or XML?

I am working with this Web Page for improving my programming skills:
http://www.studenti.ict.uniba.it/esse3/ListaAppelliOfferta.do
If you take a look at its source code, you can see HTML peculiar tags like
<head> <body> <title>
The question is: I am quite sure this page is not in XML, so is it simple HTML or XHTML?
According to my knowledge those two are quite similar.
How can I tell which of the two it is? If I must choose I'd say simple HTML (5 or 4) but I am not 100% sure!
Look for a Doctype declaration at the very beginning of the document.
If it is XHTML, the doctype will look like this:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
If it is HTML5, it will look like this:
<!DOCTYPE html>
See the W3 Spec for information on Doctype. More information here at the Mozilla Developer Network, too.
The Website you linked has <!DOCTYPE html> declared, which instructs the browser to interpret the document as HTML5 markup.
The <!DOCTYPE html> declaration indicates that it is HTML5. Of course, it might not actually be HMTL5, but it's claiming that it is. The only way to be sure is to run it through an HTML5 validator.

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

From: http://www.w3schools.com/tags/tag_doctype.asp
The < !DOCTYPE > declaration is not an HTML tag; it is an instruction to
the web browser about what version of HTML the page is written in.
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.
Tip: Always add the < !DOCTYPE > declaration to your HTML documents, so that the browser knows what type of document to expect.
Does the bold statement mean that when we are using HTML 5 we don't need to specify < !DOCTYPE html >?
What does that statement exactly mean?
I am currently using < !DOCTYPE html > in my html file with the browser Firefox 4. I removed that declaration but did not see any difference in the rendered output. Does it mean that the problem may occur in old browsers and not in new ones?
The terminology is confusing, but a DTD (document type definition) is only one part of a document type declaration (usually shortened to "doctype"). You should always include a doctype declaration (<!DOCTYPE html> if you use HTML5), but a document type definition identifier is no longer necessary.
To provide a concrete example, this is what a HTML4.01 document type declaration ("doctype") might have looked like:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
The document type definition ("DTD") identifier in the above declaration is this part:
"-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"
That's the part you can leave off for HTML5. "PUBLIC" specifies the DTD's availability, so that should also not be included if there is no DTD.
Does the bold statement mean that when we are using HTML 5 we don't need to specify ?
It means that you can't specify.
The HTML 5 Doctype has no public or system identifier in it.
I am currently using <!DOCTYPE html> in my html file
That is required. Keep doing that.
with the browser Firefox 4.
The current stable version of Firefox is version 20. You should probably upgrade.
I removed that declaration but did not see any difference in the rendered output. Does it mean that the problem may occur in old browsers and not in new ones?
No, it just means that you don't have any code that is impacted by being in Quirks mode (or that you do but didn't spot the changes).
Lets take a look at the W3C HTML5 definition, they have a conveniënt page about the differences HTML5 brings:
http://www.w3.org/TR/html5-diff/#doctype
2.2 The Doctype
The HTML syntax of HTML5 requires a doctype to be specified to ensure
that the browser renders the page in standards mode. The doctype has
no other purpose. [DOCTYPE]
The doctype declaration for the HTML syntax is and is
case-insensitive. Doctypes from earlier versions of HTML were longer
because the HTML language was SGML-based and therefore required a
reference to a DTD. With HTML5 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 .
To support legacy markup generators that cannot generate the preferred
short doctype, the doctype is allowed in the HTML syntax.
The strict doctypes for HTML 4.0, HTML 4.01, XHTML 1.0 as well as
XHTML 1.1 are also allowed (but are discouraged) in the HTML syntax.
In the XML syntax, any doctype declaration may be used, or it may be
omitted altogether. Documents with an XML media type are always
handled in standards mode.
On that page, chapter 1 (Introduction) says more about HTML versus XML syntax:
The HTML5 draft (..) defines a single language called HTML which can be written in HTML syntax and in XML syntax.
So, if your HTML5 is strict XML syntax, i can conclude from the last paragraph that yes in this case you should not prefix a doctype line.
See chapter 2 for the difference in syntax:
HTML5 HTML syntax:
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Example document</title>
</head>
<body>
<p>Example paragraph</p>
</body>
</html>
HTML5 XML syntax:
<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Example document</title>
</head>
<body>
<p>Example paragraph</p>
</body>
</html>
There is some subtle differences in syntax.

Are there different HTML5 doctypes?

When I use to write pages in XHTML. I had 3 types of doctype - strict, transitional and frameset.
Do we have them in HTML5?
the html5 doctype is
<!DOCTYPE html>
When you use the new HTML5 DOCTYPE, it triggers browsers to render the page in standards compliant mode.
Standards-compliant mode
In standards-compliant mode, the web browser assumes the page has been authored to the web content specification declared; code that does not conform to the declared standard may not display, or may display incorrectly.
For a web browser’s standards-compliant mode to be triggered, the webpage must have a complete document type declaration, including the URI to the document type definition (DTD).
There is typically less variation in webpage display between different browsers when standards-compliant mode is triggered, as the same centralised W3C specification is used as a reference when creating the web browser software.
Courtesy this link
No, the HTML5 doctype
<!DOCTYPE html>
is unique, since it was chosen as the shortest doctype (string) able to turn all current browser (even IE6, afaik) in standard mode (and it can be written in upper/mixed case)
HTML 5 requires a doctype for legacy compatibility. It has a short doctype <!DOCTYPE html> and a long doctype <!DOCTYPE html SYSTEM "about:legacy-compat"> The long doctype is only for systems that cannot generate the short one. - HTML 5 specification
No, HTML5 is just HTML5, there are no subsets.
There is but one:
<!DOCTYPE html>
The standard required preamble in the HTML serialisation of HTML5 (i.e. when served as text/html) is
<!DOCTYPE html>
Some HTML generators, most notably XSLT, have difficulty creating the above doctype. They may use
<!DOCTYPE html SYSTEM "about:legacy-compat">
In the XML serialisation of HTML5 (i.e. when served as application/xhtml+xml), the doctype may be either of the above, or it may be omitted entirely.
Note that these variations are not like strict, transitional or frameset. What is valid and invalid in HTML5 is the same for each of the above variations - leaving aside the orthogonal matter of differences between HTML and XML syntax.
HTML5 has only one and that is:
<!DOCTYPE html>