HTML Doctypes
HTML Doctypes declared at the beginning of HTML documents, inform browsers about the document type and version, ensuring correct rendering. They aren’t HTML tags but provide essential information. The most common doctype is <!DOCTYPE html>, used for HTML5, ensuring modern web standards.
Declaration of a Doctype
A DOCTYPE declaration, appearing at the top of a web page before all other elements, is required by HTML standards. It ensures that browsers display the page as intended, adhering to the specified HTML version.
The DOCTYPE for HTML5 is case-insensitive and can be written as shown below:
< !DOCTYPE html >
Doctype Usage
- In HTML 4.01, the DOCTYPE declaration refers to a document type definition (DTD), which defines the structure and legal elements of an XML document.
- SGML Basis: HTML 4.01 is based on Standard Generalized Markup Language (SGML), necessitating a reference to a DTD in the DOCTYPE declaration.
- Strict DTD: This is used for web pages excluding outdated attributes and elements, promoting the use of CSS for styling and layout.
- Transitional DTD: This allows the use of deprecated elements and attributes, easing the transition from older HTML versions to more modern practices.
- Frameset DTD: Specifically used for web pages that utilize frames, defining the structure and permissible elements for such layouts.
Example: In this example, we will see, an HTML program with a doctype declaration:
<!DOCTYPE html>
<html>
<body>
<h1>
w3wiki
</h1>
<h2>
This is HTML5 Doctype Tag
</h2>
</body>
</html>
Output:
Below is the list of some common doctype declaration for different version of HTML and XHTML:
HTML 5
<!DOCTYPE html>
HTML 4.01 Strict
In HTML 4.01 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.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
HTML 4.01 Transitional
In HTML 4.01 Transitional document type definition (DTD) allows some older PUBLIC and attributes that have been deprecated.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
HTML 4.01 Frameset
In HTML 4.01 Frameset document type definition (DTD),Frames can be used.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN"
"http://www.w3.org/TR/html4/frameset.dtd">
XHTML 1.0 Strict
In XHTML 1.0 Strict document type definition (DTD), deprecated tags are not supported and the code must be written according to the XML Specification.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
XHTML 1.0 Transitional
In XHTML 1.0 Transitional document type definition (DTD), deprecated elements are allowed.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
XHTML 1.0 Frameset
In XHTML 1.0 Frameset document type definition (DTD), framesets can be used.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
XHTML 1.1
In XHTML 1.1 document type definition (DTD), allows the addition of modules.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
Contact Us