HTML | Doctypes

What is doctype?
A doctype or document type declaration is an instruction which 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.

Declaration of a Doctype: A DOCTYPE declaration appears at the top of a web page before all other elements. According to the HTML specification or standards, every HTML document requires a document type declaration to ensure that the pages are displayed in the way they are intended to be displayed.

The DOCTYPE for HTML5 is case-insensitive and can be written as shown below:

< !DOCTYPE html >

Doctype Usage: In the version, HTML 4.01, the usage of DOCTYPE declaration was to create a reference to a document type definition (DTD), since the version HTML 4.01 was completely based on a Standard Generalized Markup Language(SGML).

The document type definition (DTD) is responsible for specifying the rules for the Standard Generalized Markup Language(SGML) so that the browser processes the content correctly. But in the HTML version, HTML 5 there isn’t any need of a reference to a document type definition (DTD) because HTML 5 is not based on a Standard Generalized Markup Language(SGML).

In HTML 5, the DOCTYPE declaration is only required for enabling the standard mode for writing documents.

Below is a sample HTML program with doctype declaration:
Example:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
  
<head>
    <title>HTML Doctypes</title>
</head>
  
<body>
  <p>HTML is easy to learn.</p>
</body>
  
</html>

chevron_right


Output:

HTML is easy to learn.

Below is the list of some common doctype declaration for differenet version of HTML and XHTML:

  1. HTML 5

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    <!DOCTYPE html>

    chevron_right

    
    

  2. 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.

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"

    chevron_right

    
    

  3. HTML 4.01 Transitional
    In HTML 4.01 Transitional document type definition (DTD) allows some older PUBLIC and attributes that have been deprecated.

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"

    chevron_right

    
    

  4. HTML 4.01 Frameset
    In HTML 4.01 Frameset document type definition (DTD),Frames can be used.

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN"

    chevron_right

    
    

  5. 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.

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 

    chevron_right

    
    

  6. XHTML 1.0 Transitional
    In XHTML 1.0 Transitional document type definition (DTD),deprecated elements are allowed.

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 

    chevron_right

    
    

  7. XHTML 1.0 Frameset
    In XHTML 1.0 Frameset document type definition (DTD),framesets can be used.

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" 

    chevron_right

    
    

  8. XHTML 1.1
    In XHTML 1.1 document type definition (DTD),allows the addition of modules.

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" 

    chevron_right

    
    

Supported Browsers: The browser supported by <!DOCTYPE > tag are listed below :

  • Google Chrome
  • Internet Explorer
  • Firefox
  • Opera
  • Safari


My Personal Notes arrow_drop_up

I am a technology enthusiast who has a keen interest in programming I am pursuing Engineering in Computer Science from GEU, Dehradun I like to unwind by watching movies and English sitcomsI have a keen interest in music

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



Improved By : nidhi_biet



Article Tags :
Practice Tags :


2


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.