Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML5 <script> declarations

Is it still necessary (or even good practice) when using HTML5 to declare the script type when using a script block?

e.g. <script type="text/javascript">

Plus what about using a CDATA block in the script for browser parsing?

e.g. // <![CDATA[ ... ~code here ~... // ]]>

Any help much appreciated.

like image 364
Chris Avatar asked Apr 11 '11 13:04

Chris


People also ask

What is the declaration for HTML5?

The <! DOCTYPE html> declaration is used to inform a website visitor's browser that the document being rendered is an HTML document. While not actually an HTML element itself, every HTML document should being with a DOCTYPE declaration to be compliant with HTML standards.

Where do you declare a script in HTML?

Scripts can be placed in the <body> , or in the <head> section of an HTML page, or in both.

What would happen if you didn't specify the HTML5 declaration?

<! 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,...)

How does HTML5 initialize document type?

Definition and Usage All HTML documents must start with a <! DOCTYPE> declaration. The declaration is not an HTML tag. It is an "information" to the browser about what document type to expect.


1 Answers

The current draft of HTML5 doesn't require the type attribute for script tags.

Also the <![CDATA is not required in HTML5 (it was XHTML specific anyway).

like image 148
halfdan Avatar answered Oct 15 '22 10:10

halfdan