DOCTYPE document type declaration (required for web page lovers)


Document type declaration
At the top of each page, you need a document declaration. Yes, I must.

If you don’t specify the document type, your HTML is not legal HTML, and most browsers use “quirks mode” to process pages, which means that the browser thinks you don’t know what to do, and processes your code in the browser’s own way. You can be an HTML master who is invincible all over the world, or your HTML can be flawless and CSS can be perfect, but if there is no document declaration or wrong document declaration, your web page is no different from that of a short-sighted, one eyed gibbon baby.

The document declaration of XHTML 1.0 strict is as follows:
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Strict//EN” “”>

The following is the document statement of XHTML 1.1. As the latest version of XHTML, it looks more perfect, but there are still some problems, which we will explain later
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.1//EN” “”>

Note that the DOCTYPE label must be capitalized and preceded by an English half angle exclamation mark!. It’s the only rule breaking tag and it doesn’t need to be closed.

Language declaration
Even if the XML: lang attribute is set in the HTTP header or in the HTML start tag, you must specify a main language for the document. Although it is not necessary to process a legal XHTML document, it is also an ease of use consideration. Values are abbreviated, such as en (English), fr (French), and de (German).

Declare a document whose content is mainly in English, for example:
<html xmlns=”” xml:lang=”en”>

After declaring the main language, if you need to use other languages, you can also use XML: Lang attributes in inline (such as < span XML: lang = “de” > HTML hund < / span >).

Content type
The media type and font set of HTML documents may be specified, which can be completed by using HTTP headers, such as:
Content-Type: text/html; charset=UTF-8

The first part of the HTTP header (such as text / HTML) is the file MIME type, which allows the browser to know the media type of the file, so it can know how to deal with it. All files have MIME types. JPEG images are image / jpeg, CSS files are text / CSSS and HTML, and text / html is generally used.

The second part of the HTTP header (such as the UTF-8 part) is the character set.

Perhaps the easiest way to set HTTP headers is to use the “HTTP equivalent” header tag in HTML, like this:
<meta http-equiv=”Content-Type” content=”text/html; charset=UTF-8″ />
The following is a common document declaration. In fact, Dreamweaver defaults to this declaration.

Copy code

The code is as follows:

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “”>
<html xmlns=””>
<meta http-equiv=”Content-Type” content=”text/html; charset=gb2312″ />
< title > Untitled Document < / Title >

Here are the additions to developeppaer.
CSS declaration and non declaration will lead to different control of the page. It won’t meet W3C standards or anything. Therefore, it is suggested that everyone should add. In this way, you can make multiple browsers compatible with your website.
JavaScript will have a greater impact, resulting in the previously written JS code can not run normally. Especially like couplet ads. In fact, in general, just pay attention to the following problem
Document.body.scrolltop is generally used when it is not declared;
When declaring the document type, use document. Documentelement. Scrolltop;
Here are some reference documents
Necessary for writing cross browser JavaScript code [JS multi browser compatible writing method]
JavaScript Firefox ie compatible DOM method script
There are too many convenient things. You can search more.

Recommended Today

Let you understand the main points of typescript in vernacular (III)

Three object scene General objects (method not included) As before, we should not directly restrict what is in the object. We should always have data before type restrictions. At this point, go back and add the type constraint. (an error type is specifically demonstrated) There is another problem. Here we use semicolons to separate the […]