Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What happens if I don't put a <!DOCTYPE html> in my code? Will it make any major changes?

Tags:

I'm working on several projects with HTML, and sometimes I forget to put <!DOCTYPE html>. Will it make any big or noticeable changes?

like image 321
Maxemoss Avatar asked Apr 22 '14 21:04

Maxemoss


People also ask

Is it necessary to put DOCTYPE in HTML?

All HTML need to have a DOCTYPE declared. The DOCTYPE is not actually an element or HTML tag. It lets the browser know how the document should be interpreted, by indicating what version or standard of HTML (or other markup language) is being used.

Will HTML5 work if you do not put <! DOCTYPE HTML in your .HTML file?

It can, yes.


2 Answers

The <!DOCTYPE> declaration must be the very first thing in your HTML document, before the tag.

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.

A lot of IDEs allow users to leave this out and default to a certain HTML style, but leaving it out does pose a potential threat in browser compatibility and the use of older versions of HTML.

For example: new features & tags in HTML5 such as <article>,< footer >, <header>,<nav>, <section> may not be supported if the <!DOCTYPE> is not declared.

Additionally, the browser may decide to automatically go into Quirks or Strict Mode.

like image 158
steviesh Avatar answered Dec 21 '22 23:12

steviesh


In HTML documents, browsers use a DOCTYPE in the beginning of the document to decide whether to handle it in quirks mode or standards mode.

<!DOCTYPE html> // Tells the browser that we are using HTML5. 

If document type is not mentioned, browser will go to Quirks mode. Quirks mode depends upon the web browser version, If is older version then this will not support HTML5 tags (Example: header tag, footer tag, section tag,...)

To see the different between the Quirks mode and Standard mode visit : https://developer.mozilla.org/en-US/docs/Web/HTML/Quirks_Mode_and_Standards_Mode

If you want to try this one use the below code with and without

<!DOCTYPE html>  

in your older browser like IE 8 or earlier

   `<video controls>        <source src="../videos/big_buck_bunny.mp4" type="video/mp4">        <p>Your browser does not support H.264/MP4.</p>     </video>`        

//Note : In the above code src="give your local mp4 video link in your computer"

like image 44
Muthu Kumar Avatar answered Dec 22 '22 00:12

Muthu Kumar