DOCTYPE declaration is not a normal HTML Element. It is used to tell the browser that the document being rendered is HTML. Although it isn’t an Element, every document should begin with it to be compliant with HTML standards.
DOCTYPE needs to the first line in an HTML document. All newly created documents should be declared as HTML5 (the current standard), which is declared as:
<!DOCTYPE html> <html> ... </html>
Although you shouldn’t be writing older versions of HTML yourself, you might still see examples of HTML4 (or older). You can recognize these older documents by their
DOCTYPE declaration. You might see:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> ... </html>
DOCTYPE declaration defines the document as
DTD HTML 4.01. DTD is short for Document Type Definition, a.k.a the DOCTYPE.
Modern browsers actually only use the
DOCTYPE to switch between quirks mode and standards mode. Quirks mode allows the browser to display web pages that were designed for older browsers, while standards mode turns on more modern features.
When to Require
In short, always include the
DOCTYPE declaration at the start of new pages. This ensures that the page conforms to all modern standards.