Explain the importance of Doctype in HTML ?
Doctype in HTML: HTML Doctype is most often written at the very first element of the entire HTML document. It remains wrapped inside angle brackets but it is not a tag. It is a statement or declaration. Doctype stands for Document Type. It is a statement to declare the type of the document. With the help of this statement, the developer let the browser know that the following document is an HTML document.
Meaning of Doctype: A doctype or document type declaration (DTD) is an instruction that tells the web browser about the markup language in which the current page is written. The Doctype is not an element or tag, it lets the browser know about the version of or standard of HTML or any other markup language that is being used in the document.
Syntax: In HTML5 the syntax to declare doctype is very simple but in older versions like HTML4.0.1 or XHTML 1.1, it was a little bit more complex.
In HTML 5 and above versions:
In HTML 4.0.1 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">
In HTML 4.0.1 Transitional: In HTML 4.01 Transitional document type definition (DTD) allows some older PUBLIC attributes that have been deprecated.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
In 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">
In XHTML 1.1: In XHTML 1.1 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.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
In XHTML 1.0:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
Note: The XHTML 1.1 and XHTML 1.0 also have their respective strict, transitional and frameset type declarations.
- In HTML5, if the developer skips adding the doctype declaration, the system will automatically add it during runtime.
- The doctype declaration is not upper and lower case sensitive.
<!-- All of them are correct conventions--> <!DOCTYPE html> <!DocType html> <!Doctype html> <!doctype html>
Significance of Doctype declaration:
- Doctype enforces the browser to make the best effort to follow the exact specifications being made in the HTML document while rendering.
- It prevents the browser from switching to quirks mode ( The non-standard behavior of the layout in Navigator 4 and Internet Explorer 5)
Please Login to comment...