search

Details of the tag

Nov 22, 2016 am 11:42 AM
doctype

The tag is very simple, you may not care. But have you ever carefully understood the tag? W3cschool recommends using XHTML Transitional DTD, and many people obediently set Dreamweaver's HTML document type to XHTML 1.0 Transitional by default. It has been used as a matter of course ever since. It’s true that people become lazier as they grow older, and many things are subconsciously taken for granted.

’s definition

declaration is located at the frontmost position in the document, before the tag. This tag tells the browser which HTML or XHTML specification the document uses. This tag can declare three DTD types, representing strict version, transitional version and framework-based HTML version. (If the markup in the document does not follow the DTD specified by the doctype declaration, the document may not pass code verification and may not be displayed correctly in the browser.)

Usage

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

Parsing: In the above declaration, it is declared that the root element of the document is html, which is defined in the DTD whose public identifier is defined as "-//W3C//DTD XHTML 1.0 Strict//EN". The browser will understand how to find a DTD that matches this public identifier. If it is not found, the browser will use the URL following the public identifier as the location to look for the DTD.

- : Indicates that the organization name is not registered. The Internet Engineering Task Force (IETF) and the World Wide Web Consortium (W3C) are not registered ISO organizations.

+: It is the default, indicating that the organization name has been registered.

DTD: Specifies the public text class, that is, the type of object being referenced. Default is DTD.

HTML: Specify a public text description, a unique, descriptive name for the public text being referenced. A version number can be attached at the end. Default is HTML.

URL: Specifies the location of the referenced object.

Strict: Exclude all representative attributes and elements that W3C experts want to phase out.

Three HTML document types

HTML 4.01 specifies three document types: Strict, Transitional and Frameset.

If you need clean markup and avoid clutter in the presentation layer, use the HTML Strict DTD type:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" " http://www.w3.org/TR/html4/strict.dtd">

Transitional DTD can contain rendering attributes and elements that W3C expects to move into style sheets. If the user uses a system that does not support cascading style sheets ( CSS) browser and you have to use the rendering features of HTML, use the Transitional DTD type:


Frameset DTD is used for documents with frames. The Frameset DTD is equivalent to the Transitional DTD, except that the frameset element replaces the body element:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" " http://www.w3.org/TR/html4/frameset.dtd">

Three XML document types

XHTML 1.0 specifies three XML document types: Strict, Transitional, and Frameset.

If you need clean markup and avoid clutter in the presentation layer, use the XHTML Strict DTD type:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

Transitional DTD can contain the rendering attributes and elements that W3C expects to move into style sheets. If the user uses a system that does not support cascading style sheets ( CSS) browser so that you have to use the rendering features of HTML, use the Transitional DTD type:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

Frameset DTD is used for documents with frames. The Frameset DTD is equivalent to the Transitional DTD, except that the frameset element replaces the body element:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">

Choose the right doctype

In order to get the correct doctype declaration, the key is to make the DTD correspond to the standard that the document follows. For example, assuming that the document follows the xhtml 1.0 strict standard, the document's doctype declaration should reference the corresponding dtd.

On the other hand, if the doctype declaration specifies an xhtml dtd, but the document contains old-style html markup, it is inappropriate; similarly, if the doctype declaration specifies an html dtd, but the document contains xhtml 1.0 The strict tag is also inappropriate.

If no valid doctype declaration is specified, most browsers will use a built-in default dtd. In this case, the browser will use the built-in dtd to try to display the tag you specify (but this is what happens when the page is poorly written).

I looked at JD.com, Taobao, and Blog Park, and they all use this one (I have always used this one):

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

But I found that Baidu and Google use "", I checked the information carefully and found that HTML5 also uses this directly, but because HTML 5 is not based on SGML, there is no need to reference the DTD, but a doctype is needed to regulate the behavior of the browser (let the browser follow what they should way to operate).

It is recommended to use "" directly in the future. Using will turn on the standard compatibility mode of the browser. In the standard compatibility mode, it is not guaranteed to be compatible with other versions (before IE6, Just ignore it), Internet Explorer remains compatible, the rendering behavior of the document may be different from that of future Internet Explorer, but please feel free to use it~~

PS: XHTML 1 is the XMLization of HTML 4.01, which is a different Forward compatible format. The doctype in HTML 4.01 requires a reference to the DTD because HTML 4.01 is based on SGML. SGML specifies a standard format for embedding description tags in documents and specifies a standard method for describing the structure of a document. The HTML format currently used on the WEB is one that uses a fixed set of tags.


Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
What are self-closing tags? Give an example.What are self-closing tags? Give an example.Apr 27, 2025 am 12:04 AM

Self-closingtagsinHTMLandXMLaretagsthatclosethemselveswithoutneedingaseparateclosingtag,simplifyingmarkupstructureandenhancingcodingefficiency.1)TheyareessentialinXMLforelementswithoutcontent,ensuringwell-formeddocuments.2)InHTML5,usageisflexiblebutr

Beyond HTML: Essential Technologies for Web DevelopmentBeyond HTML: Essential Technologies for Web DevelopmentApr 26, 2025 am 12:04 AM

To build a website with powerful functions and good user experience, HTML alone is not enough. The following technology is also required: JavaScript gives web page dynamic and interactiveness, and real-time changes are achieved by operating DOM. CSS is responsible for the style and layout of the web page to improve aesthetics and user experience. Modern frameworks and libraries such as React, Vue.js and Angular improve development efficiency and code organization structure.

What are boolean attributes in HTML? Give some examples.What are boolean attributes in HTML? Give some examples.Apr 25, 2025 am 12:01 AM

Boolean attributes are special attributes in HTML that are activated without a value. 1. The Boolean attribute controls the behavior of the element by whether it exists or not, such as disabled disable the input box. 2.Their working principle is to change element behavior according to the existence of attributes when the browser parses. 3. The basic usage is to directly add attributes, and the advanced usage can be dynamically controlled through JavaScript. 4. Common mistakes are mistakenly thinking that values ​​need to be set, and the correct writing method should be concise. 5. The best practice is to keep the code concise and use Boolean properties reasonably to optimize web page performance and user experience.

How can you validate your HTML code?How can you validate your HTML code?Apr 24, 2025 am 12:04 AM

HTML code can be cleaner with online validators, integrated tools and automated processes. 1) Use W3CMarkupValidationService to verify HTML code online. 2) Install and configure HTMLHint extension in VisualStudioCode for real-time verification. 3) Use HTMLTidy to automatically verify and clean HTML files in the construction process.

HTML vs. CSS and JavaScript: Comparing Web TechnologiesHTML vs. CSS and JavaScript: Comparing Web TechnologiesApr 23, 2025 am 12:05 AM

HTML, CSS and JavaScript are the core technologies for building modern web pages: 1. HTML defines the web page structure, 2. CSS is responsible for the appearance of the web page, 3. JavaScript provides web page dynamics and interactivity, and they work together to create a website with a good user experience.

HTML as a Markup Language: Its Function and PurposeHTML as a Markup Language: Its Function and PurposeApr 22, 2025 am 12:02 AM

The function of HTML is to define the structure and content of a web page, and its purpose is to provide a standardized way to display information. 1) HTML organizes various parts of the web page through tags and attributes, such as titles and paragraphs. 2) It supports the separation of content and performance and improves maintenance efficiency. 3) HTML is extensible, allowing custom tags to enhance SEO.

The Future of HTML, CSS, and JavaScript: Web Development TrendsThe Future of HTML, CSS, and JavaScript: Web Development TrendsApr 19, 2025 am 12:02 AM

The future trends of HTML are semantics and web components, the future trends of CSS are CSS-in-JS and CSSHoudini, and the future trends of JavaScript are WebAssembly and Serverless. 1. HTML semantics improve accessibility and SEO effects, and Web components improve development efficiency, but attention should be paid to browser compatibility. 2. CSS-in-JS enhances style management flexibility but may increase file size. CSSHoudini allows direct operation of CSS rendering. 3.WebAssembly optimizes browser application performance but has a steep learning curve, and Serverless simplifies development but requires optimization of cold start problems.

HTML: The Structure, CSS: The Style, JavaScript: The BehaviorHTML: The Structure, CSS: The Style, JavaScript: The BehaviorApr 18, 2025 am 12:09 AM

The roles of HTML, CSS and JavaScript in web development are: 1. HTML defines the web page structure, 2. CSS controls the web page style, and 3. JavaScript adds dynamic behavior. Together, they build the framework, aesthetics and interactivity of modern websites.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.