下面的文章提供了 DOCTYPE HTML 的概述。在 html 文件類型中,用於聲明使用者指令,並使用 html、xml 編碼本身等標(biāo)記語(yǔ)言將資料轉(zhuǎn)換為 Web 瀏覽器。我們已將文檔類型聲明為文檔的初始步驟。一般來(lái)說(shuō),DOCTYPE 不考慮任何標(biāo)籤、元素或?qū)傩?;它有助於識(shí)別標(biāo)記語(yǔ)言的版本。 tag 是 html 標(biāo)記語(yǔ)言的根標(biāo)籤或元素。它還有助於儲(chǔ)存和保存所有的網(wǎng)頁(yè)內(nèi)容,並且它會(huì)告訴使用者瀏覽器識(shí)別它是否是 html 語(yǔ)言,但使用 。在相同的網(wǎng)頁(yè)瀏覽器上顯示使用者網(wǎng)頁(yè)文件所使用的 html 語(yǔ)言版本。
什麼是 DOCTYPE HTML?
- DOCTYPE 只是一個(gè)文件類型聲明,它是一組必須與特定 html、xml 或 sgxml Web 文件關(guān)聯(lián)的指令。
- 由於某些遺留原因,如果開(kāi)發(fā)人員省略了 DOCTYPE,那麼 Web 瀏覽器將傾向於使用不同類型的渲染模式,這些模式可能與某些瀏覽器規(guī)範(fàn)以及使用者應(yīng)用程式不相容。
- 它也被標(biāo)記為一個(gè)不包含結(jié)束標(biāo)籤的空元素,因此我們不能在 中包含任何邏輯內(nèi)容。
- 我們使用 HTML 4.01 版本中的聲明也指相同的文件類型聲明,因?yàn)?HTML 4.01 版本是基於 SGML,但在 HTML5 中並不基於 SGML 語(yǔ)言。
文法:
當(dāng)我們使用 HTML 或任何標(biāo)記語(yǔ)言時(shí),我們?yōu)槊總€(gè)標(biāo)籤和元素都有一組語(yǔ)法,與文件類型聲明中相同。
以下是聲明 的基本語(yǔ)法html 文件中的模型。
<!DOCTYPE html>
<html>
<head>
</head>
<body>
---Some Front End logic ,codes,tags,elements---
</body>
</html>
為什麼我們要使用 DOCTYPE HTML?
- 因?yàn)镠tml版本需要它,假設(shè)當(dāng)時(shí)用戶應(yīng)用程式有任何問(wèn)題,我們很容易識(shí)別出根源,因?yàn)樗_實(shí)發(fā)生在HTML版本相容性或用戶瀏覽器相容性上;此外,與當(dāng)前版本和以前的版本相比,某些html 標(biāo)籤可能會(huì)被棄用。
- 因此使用者可以根據(jù) Web 應(yīng)用程式工作流程輕鬆識(shí)別問(wèn)題。
- 在 HTML 中,W3C 是 之一。像 IETF 這樣的組織,每個(gè) html 頁(yè)面都有一個(gè)唯一的標(biāo)籤“OwnerID”,它指示 html 實(shí)體的名稱或負(fù)責(zé)創(chuàng)建或維護(hù)基於 DTD 的文檔的組織的名稱。
- DTD 也稱為“公共文字類別”,它是一種物件類型,還引用了必須遵循 Web 和瀏覽器支援的 html 標(biāo)籤和元素。
- HTM/XHTML DTD 將支援它。
我們?cè)?HTML 中使用 DOCTYPE 的 HTML 版本不同?
- 如果我們使用 strict 作為 DOCTYPE,它不允許使用 html 元素編寫(xiě)表示屬性,而我們需要像 Web 應(yīng)用程式中那樣的要求,並且它不支援包含 html 框架。
- Html 4.0 有嚴(yán)格的和過(guò)渡的 DOCTYPE。
- 在嚴(yán)格的 DOCTYPE 中,使用者會(huì)使用某些 html 元素和屬性,而在嚴(yán)格的 DOCTYPE 中則不允許和允許使用它們。
- 有時(shí)html 4.0版本支援frameset,每個(gè)html文檔都必須在網(wǎng)頁(yè)上建立以上三種文檔類型聲明。
- 如果我們使用 html strict,則文件類型包括不建議使用的元素或不接受的標(biāo)籤之外的所有 html 元素、屬性。這些標(biāo)籤和元素集將出現(xiàn)在框架集中。
- 如果我們使用 html 過(guò)渡,它也支援所有 html 元素,包括已棄用的標(biāo)籤/元素。
- 在 html 框架集中,它支援我們?cè)?html 過(guò)渡 dtd 中使用以及用於聲明框架集的所有 html 元素。
- 在 html 5 中僅支援一種聲明類型,我們使用 ;此聲明僅允許 html 5 版本,但在 html 4 中,我們將使用不同版本的 dtd 規(guī)範(fàn)。
- 在 HTML 中,DOCTYPE 不區(qū)分大小寫(xiě),因此我們使用 DOCTYPE 聲明,並且它會(huì)同時(shí)以小寫(xiě)和大寫(xiě)字母書(shū)寫(xiě)。
DOCTYPE HTML 範(fàn)例
以下是範(fàn)例:
範(fàn)例#1
代碼:
<!DOCTYPE html>
<html>
<head>
<title>Sample</title>
</head>
<body>
<p>Welcome To My Domain
</p>
</body>
</html>
輸出:

範(fàn)例#2
代碼:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title> Sample Example for Strict DTD </title>
</head>
<body>
<a href><h1>Please Click </h1></a>
<marquee> Welcome To My Domain </marquee>
</body>
</html>
輸出:

範(fàn)例#3
代碼:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN"
"http://www.w3.org/TR/html4/frameset.dtd">
<html>
<head>
<title> Frameset DTD Example </title>
</head>
<frameset cols="23%,*,43%">
<frame src="first.html">
<frame src="second.html">
<frame src="third.html">
</frameset>
</html>
Output:

In the above set of examples, we will see the sample and basic dtd usages in html. In the first example, we use the that is come under the html5 version. So we use normal and basic html codings. In the second example, we use strict dtd in html 4 version so it will accept the particular tags and elements; it will not be allowed to use the deprecated tag elements in the second example, but in the last example, we use the frameset dtd in the html documents it allows the deprecated elements as well as whatever we use the html 4 transitional dtd elements and also will include the frameset tag elements.
Conclusion
In html will use DOCTYPE as a better choice for creating the web-based applications, and also it will be helpful for the website users browsers that the document is related to the html based documents. If we suppose will not use the html tag elements in the inside of the document that should be with the DOCTYPE declaration, it must be must with the html standards with the help of web browsers, and templates will check the html standards.
以上是文檔類型 HTML的詳細(xì)內(nèi)容。更多資訊請(qǐng)關(guān)注PHP中文網(wǎng)其他相關(guān)文章!