Why does my website work without the <!DOCTYPE html> tag?

Question

Why does my website work without the <!DOCTYPE html> tag?

Answer

The <!DOCTYPE html> declaration is a mandatory instruction for the browser; it tells the browser which version of HTML the HTML document is written in, currently HTML5. Without the declaration, some browsers will render HTML5 content correctly, however, other browsers may render the HTML document in a previous version of HTML, and may cause other unexpected behavior (like affecting the CSS, scripts, etc).

4 Likes

The DOCTYPE presence is an instruction for the browser as to how it will render your HTML and CSS. Without it you fall into quirk mode instead of standard mode. Quirk mode will cause the browser to mimic rendering for older browsers rather than following new standards (formatting, cell sizing etc.) of a newer website. This means your new website may not render the same way but it will still render. It will just render in a way an older browser may have rendered rather than with all the new standards.

4 Likes