Reputation: 4835
Could someone help me understand the difference between document type and content type of an html/xhtml page?
I know that document type is used by the browsers to determine which mode(standards/quirks) to choose and also to follow which document type schema to be used?
Upvotes: 4
Views: 2940
Reputation: 724452
The document type declaration is there mainly for
The HTML5 doctype declaration is solely there for triggering standards mode in browsers, since HTML5 has no document type definition.
The content type is what determines whether a page is served as HTML markup or XML-serialized (XHTML) markup.
Then what is the content type we specify in meta tags?
For HTML, it is text/html
. This is the default for most Web pages.
For XHTML, it is (usually) application/xhtml+xml
.
There's also a character encoding, typically charset=utf-8
.
This usually doesn't matter, though; in most cases the content type will be sent in the Content-Type HTTP header by the server. When a browser picks up the header it will ignore the meta tag.
In HTML5 only the charset is specified:
<meta charset="UTF-8">
Does it have any relation/difference to document type?
No.
How is this content type significant when comes to page rendering?
The same markup, assuming it is well-formed XML, can produce different DOMs in certain cases when it is served as application/xhtml+xml
as opposed to text/html
. These differences are minor, but may have different effects on page rendering.
You can write markup that will produce identical DOMs whether served as HTML or XHTML. This is known as polyglot markup.
Does specifying content type help the browser in terms of performance?
No.
Also, what all content types are there?
Concerning HTML/XHTML there are only the two I've mentioned. All the other content types (or MIME types) are irrelevant here.
Upvotes: 2
Reputation: 522567
The HTTP Content-Type
header, for which the http-equiv="Content-Type"
HTML meta tag is a fallback only, signifies what general type of document the document is. Is it a text/html
document and should the browser fire up its HTML parser? Or is it an application/pdf
document and the browser needs to load its PDF plugin? Or is it something completely different? This header/tag should also specify the encoding the document is in, if applicable.
The HTML Document Type specifies the exact type and version of the HTML document. Is it an HTML 5 document? HTML 4 Strict? Transitional? Or just legacy tag soup?
Upvotes: 6
Reputation: 2511
Upvotes: 0
Reputation: 7449
HTML Document Type
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.
Source: w3schools
While
Content Type
The content attribute gives the value associated with the http-equiv or name attribute.
Source: w3schools
Upvotes: 0