3

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>
4
  • Did you mean a page with and without <html> tag?
    – TopQnA
    Commented Jul 11, 2017 at 4:06
  • No. I mean <!DOCTYPE html><html><head></head><body></body></html> without <!DOCTYPE html> Commented Jul 11, 2017 at 4:08
  • It might be worthwhile to note that every page rendered by a server should be assigned a declaration telling the server how it's coded: - HTML5: <!DOCTYPE html> - CSS: @charset"UTF-8"; - XML: <?xml version="1.0" encoding="UTF-8" ?> - PERL/CGI: #!/usr/bin/perl -w and so on and so forth...
    – elbrant
    Commented Dec 30, 2018 at 19:00
  • 1
    I'm voting to close this question as off-topic because this is a markup question that should have been asked on Stack Overflow. It is not a webmastering question as defined in the Help Center.
    – Rob
    Commented Dec 31, 2018 at 16:24

3 Answers 3

3

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.

1
  • 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.
    – Rob
    Commented Dec 31, 2018 at 16:26
3

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.

3
  • 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.
    – Rob
    Commented Dec 31, 2018 at 16:22
  • Im glad you haven't encountered this problem. I did, which got resolved with a doctype. While back now, IE7/8 era.
    – Martijn
    Commented Dec 31, 2018 at 18:54
  • 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.
    – Rob
    Commented Dec 31, 2018 at 19:54
1

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.

1
  • This only repeats part of what was stated in the question and, otherwise, doesn't answer the question at all.
    – Rob
    Commented Dec 31, 2018 at 16:20

Not the answer you're looking for? Browse other questions tagged or ask your own question.