What will happen if I don't include the HTML DOCTYPE tag?

6,425

Solution 1

Unexpected issues is what will happen. Some HTML will get rendered oddly, some css will behave unexpected, not sure what JS will do, but I would not be surprised that that'll result in something quirky also.

There really isn't a reason not to do so (apart from some very very very edge cases). Everything might work exactly as you want to. And it could also be that you've created one of those odd situation. And you will spent a lot of time debugging for something that should just work, but somehow doesn't.

Solution 2

Nowadays browsers will auto correct a lot of issues found within the markup of the webpage, however older browsers not so much. So while you see no problem is not necessary true for other visitors.

So I advise that you have valid code to ensure that your website is displayed correctly not just to some visitors, but to all.

Solution 3

It is always recommended to define the doctype at the beginning.

https://www.w3schools.com/tags/tag_doctype.asp

SEO Aspect: Google does relatively good job with reading incorrect syntaxes.

There is something called "Best Practice" and it's always good to implement best practice just to ensure you may not have any issues.

Share:
6,425

Related videos on Youtube

Subhajit Gorai
Author by

Subhajit Gorai

Updated on September 18, 2022

Comments

  • Subhajit Gorai
    Subhajit Gorai over 1 year

    I know adding <!DOCTYPE html> (if using HTML5) on the first line is mandatory. What will happen if I don't include it? Because my site still looked the same when I removed it.

    <!DOCTYPE html>
    <html>
    <head>...</head>
    <body>...</body>
    </html>
    
  • Arne Kröger
    Arne Kröger over 5 years
    This only repeats part of what was stated in the question and, otherwise, doesn't answer the question at all.
  • Arne Kröger
    Arne Kröger over 5 years
    HTML will not be rendered oddly. It has no effect on JavaScript. And CSS will not behave unexpectedly because the behavior is defined by "quirks mode" which is where one is if one does not use a doctype.
  • Arne Kröger
    Arne Kröger over 5 years
    Any issues surrounding a missing doctype will not be corrected by browsers because not having a doctype puts you into "quirks mode" and that is defined behavior.
  • Martijn
    Martijn over 5 years
    Im glad you haven't encountered this problem. I did, which got resolved with a doctype. While back now, IE7/8 era.
  • Arne Kröger
    Arne Kröger over 5 years
    I'm not saying not including a doctype isn't a problem. One should never be in quirks mode and always have a doctype. I'm saying not having a doctype doesn't do what you think it does.