+ 19

Is it still relevant to put <!DOCTYPE html> at the beginning of an html file?

When I was in high school, my teacher said to do it for older browsers, but is that still an issue?

2nd Feb 2017, 4:24 AM
sniperisdemoman
sniperisdemoman - avatar
66 ответов
+ 42
If you dont put a doctype declaration, browsers ( at least desktop ) 'quirks mode' will interpret your page as the oldiest version of Html or undeterminated... The quirks mode is a way of operating web browsers ( at least desktop ). Basically, quirks mode ( also called compatibility mode ) means that a relatively modern browser intentionally simulates many bugs in older browsers, especially IE 4 and IE 5. The quirks mode is triggered by the sniffing doctype also known as doctype switching. This means that the browser inspects the beginning of an HTML document to see if it contains a doctype declaration as required by the HTML specification. The purpose of the quirks mode is to make the old pages appear as their author wanted. Old pages may have been written to use the known characteristics of old browsers or at least to adapt to them. You would find deeper informations about quirks mode in the following link: http://www.cs.tut.fi/~jkorpela/quirks-mode.html
2nd Feb 2017, 6:42 AM
visph
visph - avatar
+ 23
<!DOCTYPE HTML> tells the browser that you are using HTML5 (which is the way to go), so make sure its there :)
2nd Feb 2017, 5:49 AM
Nikolai Russev
Nikolai Russev - avatar
+ 18
Clearly, you can write your page without DOCTYPE declaration and it will work fine on your browser. But, if you are gonna build something live, I mean that you will upload the website to a server and get a domain like www.example.com... In that case, you need to add the DOCTYPE declaration because you don't know which browser your users will be using! Briefly, if you are practicing it is not neccessary, if you are working on a website that users can access to, you need to make your page compatible with wood user of them. 😀✌
2nd Feb 2017, 1:28 PM
Yahya Elharony
Yahya Elharony - avatar
+ 13
The <!DOCTYPE> declaration is not an HTML tag; it is an instruction to the web browser about what version of HTML the page is written in. In HTML 4.01, the <!DOCTYPE> declaration refers to a DTD, because HTML 4.01 was based on SGML. The DTD specifies the rules for the markup language, so that the browsers render the content correctly. HTML5 is not based on SGML, and therefore does not require a reference to a DTD. Always add the <!DOCTYPE> declaration to your HTML documents, so that the browser knows what type of document to expect.
3rd Feb 2017, 6:43 PM
Ranjeet Kumar
+ 8
This way you tell the browser it is HTML5. It is a good practice.
2nd Feb 2017, 5:49 AM
Иван Иванов
Иван Иванов - avatar
+ 8
I advice you stick to that principal. Most browsers will interpret you work as an old version of HTML and I'm sure you won't like that.
2nd Feb 2017, 3:15 PM
Ibejih
Ibejih - avatar
+ 7
HTML 5 has new features ..which is not uses in html4 if u don't mention that this is html 5..browser may not support some functions that's why we need to mention so that our coding work perfectly hope u got it :)
3rd Feb 2017, 1:04 PM
Siddiqui Shazia
Siddiqui Shazia - avatar
+ 7
Yes, it's mandatory. This helps browsers understand what version of HTML is used in the page.
3rd Feb 2017, 11:27 PM
Ismail
Ismail - avatar
+ 6
Do it to be an up to date programmer. :-)
3rd Feb 2017, 12:33 AM
Isaac Gounton
Isaac Gounton - avatar
+ 5
Writing<!DOCTYPE HTML> tells your browser that you are using HTML5.You can omit that but your browser may not work properly.
10th Feb 2017, 5:25 AM
keivan Ipchi
keivan Ipchi - avatar
+ 4
Yes it is very much relevant to have a doctype declaration at the beginning of your HTML document. It saves your browser from trying to guess what version of HTML you are using. If you use <!DOCTYPE html>, your web browser will know that the web page is written in HTML5 and will correctly render all the HTML5 features used in the document that are supported by the user's web browser. So, not only does it help your browser the strain to guess the HTML version, but also ensures correct rendering of the HTML features.
3rd Feb 2017, 12:10 PM
Walter Adhao
Walter Adhao - avatar
+ 3
it isnt realy, depends if you want to build a homepage etc. to run on a server... for private use its not necessarry.
2nd Feb 2017, 5:08 PM
Google Google
Google Google - avatar
+ 3
Doctype html say only that this is a html5 document..
3rd Feb 2017, 9:31 AM
Claas Leo
Claas Leo - avatar
+ 3
no it's not,unless you are using any tag or attribute introduced in HTML5.<!DOCTYPE html> is a syntax used to clarify the browser that the code is written in 5th version of HTML.
3rd Feb 2017, 11:31 AM
Nishant Amoli
Nishant Amoli - avatar
+ 3
<!DOCTYPE html> tells your browser that file has been written using HTML5
3rd Feb 2017, 4:36 PM
Anan Hamad
+ 3
yes, because this make your HTML to become a html5
4th Feb 2017, 5:34 PM
Thiago Sousa Della Noce
Thiago Sousa Della Noce - avatar
+ 3
You can specify what you want to use like HTML 4 or 5, XML or XHTML
9th Feb 2017, 4:31 AM
Sean He
Sean He - avatar
+ 3
@Vishwajeet Sharma wrote: "<!DOCTYPE> is a declaration to the browser that will show you page it says hey browser this page is written in HTML4 or 5 .." <!DOCTYPE> isn't Html specific... and <DOCTYPE html> is for Html5 and beyond. Previous vesions of X/Html had also doctypes, but ugly: HTML 4.01 - Strict <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> HTML 4.01 - Transitional<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> HTML 4.01 - Frameset <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd"> HTML 3.2 - DTD <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> HTML 2.0 - DTD <!DOCTYPE html PUBLIC "-//IETF//DTD HTML 2.0//EN"> XHTML 1.1 - DTD <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> XHTML Basic 1.1 (quick reference): <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Basic 1.1//EN" "http://www.w3.org/TR/xhtml-basic/xhtml-basic11.dtd"> XHTML 1.0 - Strict (quick reference) <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> XHTML 1.0 - Transitional <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> XHTML 1.0 - Frameset <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd"> XHTML Basic 1.0 - DTD <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Basic 1.0//EN" "http://www.w3.org/TR/xhtml-basic/xhtml-basic10.dtd"> Now, don't you feel the Html5 doctype so sexy? :P
16th Feb 2017, 5:18 AM
visph
visph - avatar
+ 2
yes still put <!DOCTYPE html>
3rd Feb 2017, 4:13 PM
Snow Man47
Snow Man47 - avatar
+ 2
yes.
3rd Feb 2017, 5:56 PM
Mokoto