首頁  >  文章  >  web前端  >  文檔類型 HTML

文檔類型 HTML

WBOY
WBOY原創
2024-09-04 16:45:431159瀏覽

下面的文章提供了 DOCTYPE HTML 的概述。在 html 文件類型中,用於聲明使用者指令,並使用 html、xml 編碼本身等標記語言將資料轉換為 Web 瀏覽器。我們已將文檔類型聲明為文檔的初始步驟。一般來說,DOCTYPE 不考慮任何標籤、元素或屬性;它有助於識別標記語言的版本。 tag 是 html 標記語言的根標籤或元素。它還有助於儲存和保存所有的網頁內容,並且它會告訴使用者瀏覽器識別它是否是 html 語言,但使用 。在相同的網頁瀏覽器上顯示使用者網頁文件所使用的 html 語言版本。

什麼是 DOCTYPE HTML?

  • DOCTYPE 只是一個文件類型聲明,它是一組必須與特定 html、xml 或 sgxml Web 文件關聯的指令。
  • 由於某些遺留原因,如果開發人員省略了 DOCTYPE,那麼 Web 瀏覽器將傾向於使用不同類型的渲染模式,這些模式可能與某些瀏覽器規範以及使用者應用程式不相容。
  • 它也被標記為一個不包含結束標籤的空元素,因此我們不能在 中包含任何邏輯內容。
  • 我們使用 HTML 4.01 版本中的聲明也指相同的文件類型聲明,因為 HTML 4.01 版本是基於 SGML,但在 HTML5 中並不基於 SGML 語言。

文法:

當我們使用 HTML 或任何標記語言時,我們為每個標籤和元素都有一組語法,與文件類型聲明中相同。

以下是聲明 的基本語法html 文件中的模型。

<!DOCTYPE html>
<html>
<head>
</head>
<body>
---Some Front End logic ,codes,tags,elements---
</body>
</html>

為什麼我們要使用 DOCTYPE HTML?

  • 因為Html版本需要它,假設當時用戶應用程式有任何問題,我們很容易識別出根源,因為它確實發生在HTML版本相容性或用戶瀏覽器相容性上;此外,與當前版本和以前的版本相比,某些html 標籤可能會被棄用。
  • 因此使用者可以根據 Web 應用程式工作流程輕鬆識別問題。
  • 在 HTML 中,W3C 是 之一。像 IETF 這樣的組織,每個 html 頁面都有一個唯一的標籤“OwnerID”,它指示 html 實體的名稱或負責創建或維護基於 DTD 的文檔的組織的名稱。
  • DTD 也稱為“公共文字類別”,它是一種物件類型,還引用了必須遵循 Web 和瀏覽器支援的 html 標籤和元素。
  • HTM/XHTML DTD 將支援它。

我們在 HTML 中使用 DOCTYPE 的 HTML 版本不同?

  • 如果我們使用 strict 作為 DOCTYPE,它不允許使用 html 元素編寫表示屬性,而我們需要像 Web 應用程式中那樣的要求,並且它不支援包含 html 框架。
  • Html 4.0 有嚴格的和過渡的 DOCTYPE。
  • 在嚴格的 DOCTYPE 中,使用者會使用某些 html 元素和屬性,而在嚴格的 DOCTYPE 中則不允許和允許使用它們。
  • 有時html 4.0版本支援frameset,每個html文檔都必須在網頁上建立以上三種文檔類型聲明。
  • 如果我們使用 html strict,則文件類型包括不建議使用的元素或不接受的標籤之外的所有 html 元素、屬性。這些標籤和元素集將出現在框架集中。
  • 如果我們使用 html 過渡,它也支援所有 html 元素,包括已棄用的標籤/元素。
  • 在 html 框架集中,它支援我們在 html 過渡 dtd 中使用以及用於聲明框架集的所有 html 元素。
  • 在 html 5 中僅支援一種聲明類型,我們使用 ;此聲明僅允許 html 5 版本,但在 html 4 中,我們將使用不同版本的 dtd 規範。
  • 在 HTML 中,DOCTYPE 不區分大小寫,因此我們使用 DOCTYPE 聲明,並且它會同時以小寫和大寫字母書寫。

DOCTYPE HTML 範例

以下是範例:

範例#1

代碼:

<!DOCTYPE html>
<html>
<head>
<title>Sample</title>
</head>
<body>
<p>Welcome To My Domain
</p>
</body>
</html>

輸出:

文檔類型 HTML

範例#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>

輸出:

文檔類型 HTML

範例#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:

文檔類型 HTML

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的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn