htmldoctype

What does <!doctype html> do?


What does this tag do?

<!doctype html>

I can see that with this tag on top, my HTML behaves in another way than without.

How do I know if I need this tag?


Solution

  • 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.