简体   繁体   English

html文件中的DOCTYPE HTML

[英]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: DOCTYPE声明(DTD或文档类型声明)具有以下作用:

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. 在网页上执行HTML验证测试时,它告诉HTML(超文本标记语言)验证器该网页编码应符合哪个版本的(X)HTML标准。 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). 当您验证网页时,HTML验证器会根据适用的标准检查编码,然后报告编码的哪些部分未通过HTML验证(不符合标准)。 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? 有关更多信息,请参见此“ <!DOCTYPE html>”是什么意思?

It tells the browser that the following code is to be treated as a particular version of html code. 它告诉浏览器以下代码将被视为html代码的特定版本。

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> 然后,浏览器知道要查找打开的HTML标签<html> ,并将所有内容都视为html,直到到达关闭的HTML标签</html>

<!DOCTYPE html> is all that's needed now. 现在<!DOCTYPE html>

The declaration is not an HTML tag; 该声明不是HTML标记。 it is an instruction to the web browser about what version of HTML the page is written in. 这是向Web浏览器发出的有关页面写入哪个HTML版本的指令。

In HTML 4.01, the declaration refers to a DTD, because HTML 4.01 was based on SGML. 在HTML 4.01中,该声明引用了DTD,因为HTML 4.01基于SGML。 The DTD specifies the rules for the markup language, so that the browsers render the content correctly. DTD指定标记语言的规则,以便浏览器正确呈现内容。

HTML5 is not based on SGML, and therefore does not require a reference to a DTD. HTML5不是基于SGML,因此不需要引用DTD。

Tip: Always add the declaration to your HTML documents, so that the browser knows what type of document to expect. 提示:始终将声明添加到HTML文档中,以便浏览器知道期望的文档类型。

The term DOCTYPE tells the browser which type of HTML is used on a webpage. 术语DOCTYPE告诉浏览器网页上使用哪种HTML类型。 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. doctype定义您的文档使用的HTML / XHTML版本。 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 您可能希望使用doctype,以便在通过验证程序运行代码时,验证程序知道要检查哪个版本的HTML / XHTML。

The <!DOCTYPE html> declaration is used to inform a website visitor's browser that the document being rendered is an HTML document. <!DOCTYPE html>声明用于通知网站访问者的浏览器所呈现的文档是HTML文档。 While not actually an HTML element itself, every HTML document should being with a DOCTYPE declaration to be compliant with HTML standards. 尽管实际上不是HTML元素本身,但是每个HTML文档都应带有DOCTYPE声明,以符合HTML标准。

For HTML5 documents (which nearly all new web documents should be), the DOCTYPE declaration should be: 对于HTML5文档(几乎所有新的Web文档都应为HTML5文档),DOCTYPE声明应为:

<!DOCTYPE html>

Show to the browser than the file is a HTML5. 向浏览器显示的文件不是HTML5。 Is followed by the lenguage etiquete according to HTML5 good practiques. 其次是根据HTML5良好惯例进行的语言礼节。

<!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 lang="es">

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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