Search code examples
phphtml

Should i use <!DOCTYPE html> on every file?


I understand that i should always use <!DOCTYPE html> at the beginning of my project webpage.

Is this true ONLY for the main page (index) or every html and php file must have it also?


Solution

  • You should use it on every html page just like mrlew said. This tells the browser what version on html you are using. Some strict browser can misplace some stuff and disable some other features if this line is not recognised.

    So let say you only put this on your index.html file, if the user go to another page /streamvideo and you didn't put this line, the HTML5 video player might not work.

    This being said, most common browser will 'fix' stuff like this or 'assume' you're using HTML5.

    See:

    http://www.html-5-tutorial.com/doctype.htm

    https://www.w3.org/QA/2002/04/valid-dtd-list.html

    (Sorry, I skipped the w3school link :P)

    Opening these links made me think of another example I can give you. Before HTML5, if you have frames in your web page, it would be accurate to use the frame set declaration.

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd"> 
    

    Nice example in the w3org link above. Hope this clear things out.