Reputation: 5131
David crockford recommends ommitting the type="application/javascript"
attribute for the script tag. Should I do the same for a CSS link tag (omit "type=text/css"
)? I googled "html link omit mime type" and some variants and didn't find anything
Upvotes: 3
Views: 2661
Reputation: 201568
There is no practical reason to use the type
attribute in either script
or link
elements, when you are using JavaScript and CSS, as you are (almost always). However, if there is an external requirement imposed upon you to conform to the HTML 4.01 specification, use type="text/javascript"
in script
, and double-check that you enter it correctly.
Those attributes are never needed (for JavaScript and CSS), but they hurt you if you misspell them. Then browsers will expect that your script is in text/javascript
or your style sheet is in text/ccs
and ignore it, since they do not know such languages.
In a script
element, you would need a type
attribute only if the content is not to be interpreted as JavaScript but e.g. as VBScript or not interpreted at all, just stored as data.
Upvotes: 2
Reputation: 191749
Per documentation for <script>
:
The type attribute gives the language of the script or format of the data. If the attribute is present, its value must be a valid MIME type. The charset parameter must not be specified. The default, which is used if the attribute is absent, is "text/javascript".
Now, let's take a look at <link>
:
The default value for the type attribute, which is used if the attribute is absent, is "text/css".
The specification is not clear on this for some reason, but it does contain this:
Since that default type is text/css...
The type
attribute is also purely advisory. Modern browsers definitely don't need it if it's valid CSS.
Upvotes: 4