doctype image

what is DOCTYPE ?

  • Profile picture of Mcs
  • by Mcs June 27, 2025

In HTML, a <!DOCTYPE> declaration, often called a "doctype", is a short instruction placed at the very beginning of an HTML document that tells the browser what version of HTML the page is written in.

t's not a tag or an element itself, but rather a declaration that ensures the browser renders the page in standards mode, rather than quirks mode, which can lead to inconsistencies in how the page is displayed across different browsers.

Here's a more detailed explanation:

Purpose:

Tells the browser the HTML version:

The <!DOCTYPE> declaration tells the browser which version of HTML the document is using, enabling the browser to interpret the document correctly.

Activates standards mode:

Without a doctype, browsers might enter "quirks mode," which can cause inconsistencies in how elements are displayed and make it difficult to achieve cross-browser consistency.

Ensures consistent rendering:

By specifying the doctype, developers can help ensure that web pages are rendered as intended across different browsers.

Example (HTML5):

<!DOCTYPE html>
<html>
<head>
 <title>My Web Page</title>
</head>
<body>
 <h1>Hello, world!</h1>
</body>
</html>

Key Points:

  1. The doctype should be the very first thing in your HTML document, before any other HTML tags. 
  2. It is not a tag and does not require a closing tag. 
  3. For HTML5, the declaration is simply <!DOCTYPE html>. 
  4. Different versions of HTML have different doctype declarations. 

Comments

Add new comment

Restricted HTML

  • Allowed HTML tags: <br> <p> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id> <cite> <dl> <dt> <dd> <a hreflang href> <blockquote cite> <ul type> <ol type start> <strong> <em> <code> <li>
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.