#1 Data Analytics Program in India
₹2,499₹1,499Enroll Now
4 min read
•Question 4 of 49easy

What is DOCTYPE?

Why every HTML page needs it.

What You'll Learn

  • What DOCTYPE declaration is
  • Quirks mode vs standards mode
  • HTML5 DOCTYPE syntax

What is DOCTYPE?

<!DOCTYPE html> is a declaration that tells the browser which version of HTML the document uses. It must be the very first line of your HTML file, before the <html> tag.

Why It Matters

Without DOCTYPE

Browsers enter "quirks mode" where they emulate old browser behavior for backward compatibility. This causes inconsistent rendering across browsers.

With DOCTYPE

Browsers use "standards mode" for consistent, predictable rendering.

DOCTYPE Syntax

index.htmlHTML
<!-- HTML5 (current) - simple -->
<!DOCTYPE html>

<!-- HTML 4.01 (old) - complex -->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
  "http://www.w3.org/TR/html4/strict.dtd">

<!-- Always put DOCTYPE first -->
<!DOCTYPE html>
<html>
  <head>...</head>
  <body>...</body>
</html>

Best Practice

Always use the HTML5 DOCTYPE - it's simple and works everywhere:

index.htmlHTML
<!DOCTYPE html>