DOCTYPE Document Type Declaration (Must-Read for Web Page Lovers)

DOCTYPE Document Type Declaration (Must-Read for Web Page Lovers)
DOCTYPE DECLARATION At the top of every page you write, you need a document declaration. Yes, it must.

If you don't specify a document type, your HTML is not valid HTML, and most browsers will process the page in "quirks mode", which means that the browser assumes that you don't know what to do and processes your code in its own way. You can be an HTML master, unrivaled on earth, or your HTML can be flawless and your CSS can be perfect, but if there is no document declaration, or the wrong document declaration, your web page is no different from a short-sighted, one-eyed gibbon baby who put it together with great difficulty.

The XHTML 1.0 Strict document declaration looks like this:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

The following is the document declaration for 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" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

Note that the DOCTYPE tag must be capitalized and preceded by an exclamation mark!. It's the only tab that breaks the rule, it doesn't need to be closed.

Language Declaration Even if you set the xml:lang attribute in the HTTP header or in the HTML start tag, you must specify a primary language for the document. Although this is not necessary to process a valid XHTML document, it is a usability consideration. Values ​​are abbreviations, such as en (English), fr (French), de (German).

Declare a document with mainly English content, the example is as follows:
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">

After declaring the primary language, you can also use the xml:lang attribute inline if you need to use other languages ​​(for example <span xml:lang="de">HTML Hund</span>).

Content Type
The media type and font set of an HTML document may need to be specified. This can be done using HTTP headers, for example:
Content-Type: text/html; charset=UTF-8

The first part of the HTTP header (such as text/html) is the file's MIME type, which lets the browser know the file's media type so it can know how to handle it. All files have a MIME type. JPEG images are image/jpeg, CSS files are text/csss and HTML generally uses text/html.

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 "HTTP-equivalent" header tags in HTML, like this:
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
The following is a commonly used document declaration. In fact, Dreamweaver uses this declaration by default.

Copy code
The code is as follows:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>Untitled Document</title>
</head>
<body>
</body>
</html>

Below is additional content from 123WORDPRESS.COM.
Declaring or not declaring CSS will result in different page controls. It will not conform to w3c standards or anything. So I recommend everyone to add it. This will make your website compatible with multiple browsers.
The impact of javascript will be even greater, causing previously written js codes to not run normally. Especially things like couplet advertisements. In fact, in general, you just need to pay attention to the following problem. When not declaring, generally use document.body.scrollTop;
When declaring the document type, use document.documentElement.scrollTop;
Here are some reference documents for writing cross-browser javascript code [js multi-browser compatible writing]
There are so many convenient things about javascript firefox compatible with ie's dom method scripts, you can search for it more.

<<:  CSS3 achieves cool sliced ​​image carousel effect

>>:  Summary of MySQL Undo Log and Redo Log

Recommend

Tutorial on building a zookeeper server on Windows

Installation & Configuration The official web...

A brief talk about JavaScript parasitic composition inheritance

Composition inheritance Combination inheritance i...

Sample code for batch deployment of Nginx with Ansible

1.1 Copy the nginx installation package and insta...

20 CSS coding tips to make you more efficient (sorted)

In this article, we would like to share with you ...

Steps to package and release the Vue project

Table of contents 1. Transition from development ...

How to insert 10 million records into a MySQL database table in 88 seconds

The database I use is MySQL database version 5.7 ...

MySQL 5.7.24 installation and configuration graphic tutorial

This article shares the installation and configur...

JavaScript imitates Jingdong magnifying glass effect

This article shares the specific code for JavaScr...

React-Native environment setup and basic introduction

Environment Preparation 1. Environment Constructi...

js implementation of verification code case

This article example shares the specific code of ...

How to run py files directly in linux

1. First create the file (cd to the directory whe...

MySQL export of entire or single table data

Export a single table mysqldump -u user -p dbname...

CSS3 realizes the red envelope shaking effect

There is a requirement to realize the shaking eff...

A brief analysis of the difference between static and self in PHP classes

Use self:: or __CLASS__ to get a static reference...