首页  >  文章  >  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