What does <!doctype html> do?

Niklas R. picture Niklas R. · Oct 8, 2011 · Viewed 40.2k times · Source

What does this tag do?

<!doctype html>

What I can see is that with this tag on top my html behaves in another way than without. How do I know if I need this tag?

Answer

zzzzBov picture zzzzBov · Oct 8, 2011

It's an integral part of HTML as defined in the specification:

8.1.1 The DOCTYPE

A DOCTYPE is a required preamble.

DOCTYPEs are required for legacy reasons. When omitted, browsers tend to use a different rendering mode that is incompatible with some specifications. Including the DOCTYPE in a document ensures that the browser makes a best-effort attempt at following the relevant specifications.


Edit to add:

What does this seatbelt do?

Seatbelt image

What I can see is that, with this seatbelt on, my car behaves the same way as without. How do I know if I need this seatbelt?

You wont know if you'll need it until something goes wrong and you don't have it.