📜  过渡和严格文档类型之间的区别

📅  最后修改于: 2022-05-13 01:56:37.057000             🧑  作者: Mango

过渡和严格文档类型之间的区别

在本文中,我们将看到 Transitional 和 Strict doctype 之间的区别。 Transitional 和 Strict 都是 HTML 4 中可用的文档类型。现在,什么是文档类型? doctype 声明或文档类型声明是向浏览器提供的关于它应该期望什么文档类型的信息。它不是 HTML 标记。您编码的所有 HTML 文档都应以声明开头。 doctype 声明写在 标记之上,在您编写的每个文档的开头。

Doctype声明的意义:

  • Doctype 强制浏览器在呈现时尽最大努力遵循 HTML 文档中的确切规范。
  • 它可以防止浏览器切换到怪癖模式(Navigator 4 和 Internet Explorer 5 中布局的非标准行为)

HTML5 doctype:这是当前使用的文档类型的最新版本。它没有缺点,更容易实施和召回。它将正确验证所有 HTML 5 功能以及大多数 HTML 4/XHTML 1.0 功能。旧版本 HTML 4.01 完全基于标准通用标记语言 (SGML)。因此 HTML4 中的 DOCTYPE 声明用于创建对文档类型定义 (DTD) 的引用。文档类型定义 (DTD) 负责为 SGML 指定规则,以便浏览器正确处理内容。但是在较新的 HTML 版本(即 HTML 5)中,不需要对文档类型定义 (DTD) 的引用,因为 HTML 5 不是基于 SGML。

句法:

注意: Doctype 不是 HTML 标记或元素,它不区分大小写。

示例:下面是一个带有 doctype 声明的示例 HTML 程序:

HTML


  

    
    doctype

  

    

Welcome To GFG

    

This is doctype of HTML5.

  


HTML


  

    
    doctype

  

    

Welcome To GFG

    

        
This is Transitional doctype.
    

  


HTML

  

  

    
    doctype

  

    

Welcome To GFG

    

        
This is Strict doctype.
    

  


输出 :

这是关于 doctype 及其语法的。现在让我们谈谈 Transitional 和 Strict doctype 及其区别。

过渡文档类型:

过渡文档类型根据 HTML 4.01 规范验证编写的代码。它确实允许一些表示性标记和不推荐使用的元素(例如 元素),但不允许框架集。它验证松散的 HTML 样式标记。

句法:

示例:在此示例中,整个代码将与之前相同,我们将仅使用过渡 doctype 语法。

HTML



  

    
    doctype

  

    

Welcome To GFG

    

        
This is Transitional doctype.
    

  

输出:

严格的文档类型:

严格的文档类型根据 HTML 4.01 规范验证编写的代码。但是,它不允许使用任何已弃用的元素或表示标记,例如 元素或框架集。它验证松散的 HTML 样式标记,例如,最小化的属性和未引用的属性(例如,必需的,而不是必需的 =“必需”)。

句法:

例子:在这个例子中,整个代码和我们之前一样,只是改变了doctype声明代码。

HTML


  

  

    
    doctype

  

    

Welcome To GFG

    

        
This is Strict doctype.
    

  

输出:

Transitional 和 Strict doctype 的区别:

Transitional doctypeStrict doctype
Transitional document type definition (DTD) allows some older PUBLIC and attributes that have been deprecated.Strict document type definition (DTD) all those elements and attributes are included that do not appear in frameset documents or that have not been deprecated.
 It allows presentational markup like It does not allow presentation markup like
.
Transitional doctype can be used when we have a lot of older markup that cannot be compiled with default doctype.Strict doctype is the default doctype.
There is both presentational and structural aspect in markup.It separates the presentation and structure. By not allowing presentation markup in it. All the presentation aspect is done in CSS.
By using Transitional doctype, It is not that easy to maintain the website as it mixes the presentation and structure.By using strict doctype, It is easier to maintain the website.