简体   繁体   中英

DOCTYPE HTML in html file

为什么在HTML文件中使用<!DOCTYPE html ... >

<!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 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 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 <!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">

对于构建HTML文档非常重要,它不仅是HTML,而且是向Web浏览器发出的有关页面写入哪个HTML版本的指令。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM