18

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.

1

3 Answers 3

18

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

Sign up to request clarification or add additional context in comments.

1 Comment

Btw do you have a link to the source?
6

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

HTML 5 defines text/javascript as the default, and you'd be hard pressed to find a browser that didn't treat it as such. So you can omit it.

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

Pointless unless you are writing XHTML 5 and using characters such as < or & in the script (but you should almost always be using external scripts anyway).

Comments

5

The CDATA comments are for XML, so only applicable if you're serving your pages up as xml (which you shouldn't be if it's HTML5).

As for the type attribute, it's optional now in HTML5.

1 Comment

thanks DA. I realised after i posted that the cdata wasn't necessary. I think i used to use it when coding with a XHTML strict / 1.1 doctype

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.