Does doctype is really necessary at top of the html? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Does doctype is really necessary at top of the html?

I've found that html works without having <!doctype html> at top of our document. Then what is the use of having it in our document.?

2nd Dec 2017, 2:55 AM
4 Answers
+ 8
of course it works, but the DOCTYPE action is to tell the browser what version of HTML it is running in order to validate our document, so it is always recommended to include it look this:
2nd Dec 2017, 3:09 AM
Félix Icaza
Félix Icaza - avatar
+ 3
You can drop <body> or <html> too and the site will look fine. It's invalid HTML, but browsers will play nice and fill in the gaps. Always include it, it's just one line :P
2nd Dec 2017, 3:13 AM
Schindlabua - avatar
+ 2
You can just put plain text, html still works.
2nd Dec 2017, 4:36 AM
Calviղ - avatar
+ 1
It depends whether you are using HTML4 or HTML5 HTML5 requires <! doctype html> tag at the top
2nd Dec 2017, 5:24 AM
#RahulVerma - avatar