wppaste
WordPress

WP_HTML_Doctype_Info

Since
6.7.0, 7.1.0
Source
wp-includes/html-api/class-wp-html-doctype-info.php:59
Core class used by the HTML API to represent a DOCTYPE declaration.

Description

This class parses DOCTYPE tokens for the full parser in the HTML Processor.
Most code interacting with HTML won't need to parse DOCTYPE declarations; the HTML Processor is one exception. Consult the HTML Processor for proper parsing of an HTML document.

A DOCTYPE declaration may indicate its document compatibility mode, which impacts the structure of the following HTML as well as the behavior of CSS class selectors.
There are three possible modes:

  • "no-quirks" and "limited-quirks" modes (also called "standards mode").
  • "quirks" mode.

These modes mostly determine whether CSS class name selectors match values in the HTML class attribute in an ASCII-case-insensitive way (quirks mode), or whether they match only when byte-for-byte identical (no-quirks mode).

All HTML documents should start with the standard HTML5 DOCTYPE: <!DOCTYPE html>.

DOCTYPEs are required for legacy reasons. When omitted, browsers tend to use a different rendering mode that is incompatible with some specifications. Including the DOCTYPE in a document ensures that the browser makes a best-effort attempt at following the relevant specifications.

Compatibility

WordPress
since 7.1.0
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in every tracked release (6.7.7 to 7.1.0).

Properties · 4

$namestring|nullpublic
Name of the DOCTYPE: should be "html" for HTML documents.
$public_identifierstring|nullpublic
Public identifier of the DOCTYPE.
$system_identifierstring|nullpublic
System identifier of the DOCTYPE.
$indicated_compatibility_modestringpublic
Which document compatibility mode this DOCTYPE declaration indicates.

Methods · 2

Source code

class WP_HTML_Doctype_Info {	/**	 * Name of the DOCTYPE: should be "html" for HTML documents.	 *	 * This value should be considered "read only" and not modified.	 *	 * Historically the DOCTYPE name indicates name of the document's root element.	 *	 *     <!DOCTYPE html>	 *               ╰──┴── name is "html".	 *	 * @see https://html.spec.whatwg.org/#tokenization	 *	 * @since 6.7.0	 *	 * @var string|null	 */	public $name = null; 	/**	 * Public identifier of the DOCTYPE.	 *	 * This value should be considered "read only" and not modified.	 *	 * The public identifier is optional and should not appear in HTML documents.	 * A `null` value indicates that no public identifier was present in the DOCTYPE.	 *	 * Historically the presence of the public identifier indicated that a document	 * was meant to be shared between computer systems and the value indicated to a	 * knowledgeable parser how to find the relevant document type definition (DTD).	 *	 *     <!DOCTYPE html PUBLIC "public id goes here in quotes">	 *               │  │         ╰─── public identifier ─────╯	 *               ╰──┴── name is "html".	 *	 * @see https://html.spec.whatwg.org/#tokenization	 *	 * @since 6.7.0	 *	 * @var string|null	 */	public $public_identifier = null; 	/**	 * System identifier of the DOCTYPE.	 *	 * This value should be considered "read only" and not modified.	 *	 * The system identifier is optional and should not appear in HTML documents.	 * A `null` value indicates that no system identifier was present in the DOCTYPE.	 *	 * Historically the system identifier specified where a relevant document type	 * declaration for the given document is stored and may be retrieved.	 *	 *     <!DOCTYPE html SYSTEM "system id goes here in quotes">	 *               │  │         ╰──── system identifier ────╯	 *               ╰──┴── name is "html".	 *	 * If a public identifier were provided it would indicate to a knowledgeable	 * parser how to interpret the system identifier.	 *	 *     <!DOCTYPE html PUBLIC "public id goes here in quotes" "system id goes here in quotes">	 *               │  │         ╰─── public identifier ─────╯   ╰──── system identifier ────╯	 *               ╰──┴── name is "html".	 *	 * @see https://html.spec.whatwg.org/#tokenization	 *	 * @since 6.7.0	 *	 * @var string|null	 */	public $system_identifier = null; 	/**	 * Which document compatibility mode this DOCTYPE declaration indicates.	 *	 * This value should be considered "read only" and not modified.	 *	 * When an HTML parser has not already set the document compatibility mode,	 * (e.g. "quirks" or "no-quirks" mode), it will be inferred from the properties

Changelog

Introduced in 6.7.0. Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

7.1.0
Spec update: missing and empty SYSTEM identifiers are handled the same for determining the document mode.from the docblock
6.7.0
Introduced.from the docblock

About this page

Parsed data
Generated from the wordpress-develop 7.1.0 tag, from src/wp-includes/html-api/class-wp-html-doctype-info.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.