Welcome to %s forums

<No. 1 Community for developers, by developers/>

Login Register

[Explained] - What is Doctypes in HTML5 and how to use it?

For general web development questions using HTML and CSS.
Post Reply
admin
Site Admin
Posts: 45

[Explained] - What is Doctypes in HTML5 and how to use it?

Post by admin » Sat Oct 19, 2019 7:23 pm

What is Doctype?
Doctypes - short for 'document type' - help browsers to understand the version of HTML the document is written in for better interpretability. Doctype declarations are not HTML tags and belong at the very top of a document. This topic explains the structure and declaration of various doctypes in HTML.

Adding the Doctype
The <!DOCTYPE> declaration should always be included at the top of the HTML document, before the <html> tag.

HTML5 is not based on SGML (Standard Generalized Markup Language), and therefore does not require a reference to a DTD (Document Type Definition).

HTML 5 Doctype declaration:

Code: Select all

<!DOCTYPE html>

Case Insensitivity

Per the W3.org HTML 5 DOCTYPE Spec:
A DOCTYPE must consist of the following components, in this order:
A string that is an ASCII case-insensitive match for the string "<!DOCTYPE". therefore the following DOCTYPEs are also valid:

Code: Select all

<!doctype html>
<!dOCtyPe html>
<!DocTYpe html>
Which case of doctype you should use uppercase, lowercase or camelcase?
In HTML, the DOCTYPE is case insensitive. The following DOCTYPEs are all valid:

Code: Select all

<!doctype html>
<!DOCTYPE html>
<!DOCTYPE HTML>
<!DoCtYpE hTmL>
In XML serializations (i.e. XHTML) the DOCTYPE is not required, but if you use it, DOCTYPE should be uppercase:

Code: Select all

<!DOCTYPE html>

Post Reply