What happens if I don't put a <!DOCTYPE html> in my code? Will it make any major changes?

Maxemoss picture Maxemoss · Apr 22, 2014 · Viewed 40.1k times · Source

I'm working on several projects with HTML, and sometimes I forget to put <!DOCTYPE html>. Will it make any big or noticeable changes?

Answer

steviesh picture steviesh · Apr 22, 2014

The <!DOCTYPE> declaration must be the very first thing in your HTML document, before the tag.

The <!DOCTYPE> declaration is not an HTML tag; it is an instruction to the web browser about what version of HTML the page is written in.

A lot of IDEs allow users to leave this out and default to a certain HTML style, but leaving it out does pose a potential threat in browser compatibility and the use of older versions of HTML.

For example: new features & tags in HTML5 such as <article>,< footer >, <header>,<nav>, <section> may not be supported if the <!DOCTYPE> is not declared.

Additionally, the browser may decide to automatically go into Quirks or Strict Mode.